Skip to content

Instantly share code, notes, and snippets.

@bistole
Created December 1, 2020 20:45
Show Gist options
  • Select an option

  • Save bistole/971cf4dc8cbb664e6e9ee40106e281d6 to your computer and use it in GitHub Desktop.

Select an option

Save bistole/971cf4dc8cbb664e6e9ee40106e281d6 to your computer and use it in GitHub Desktop.
fromJson and toJson
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