Created
December 1, 2020 20:45
-
-
Save bistole/971cf4dc8cbb664e6e9ee40106e281d6 to your computer and use it in GitHub Desktop.
fromJson and toJson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static AppState fromJson(dynamic json) { | |
| var tasks = <String, Task>{}; | |
| if (json is Map && json['tasks'] is Map) { | |
| json['tasks'].forEach((uuid, jsonTask) { | |
| var task = Task.fromJson(jsonTask); | |
| tasks[task.uuid] = task; | |
| }); | |
| } | |
| return AppState(status: Status.noParam(StatusKey.ListTask), tasks: tasks); | |
| } | |
| dynamic toJson() { | |
| Map<String, dynamic> ret = <String, dynamic>{}; | |
| tasks.forEach((uuid, task) { | |
| ret[uuid] = task.toJson(); | |
| }); | |
| return {"tasks": tasks}; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment