fromJson static method
Task?
fromJson(
- dynamic value
)
Returns a new Task instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Task? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
assert(json.containsKey(r'id'), 'Required key "Task[id]" is missing from JSON.');
assert(json[r'id'] != null, 'Required key "Task[id]" has a null value in JSON.');
assert(json.containsKey(r'title'), 'Required key "Task[title]" is missing from JSON.');
assert(json[r'title'] != null, 'Required key "Task[title]" has a null value in JSON.');
assert(json.containsKey(r'completed'), 'Required key "Task[completed]" is missing from JSON.');
assert(json[r'completed'] != null, 'Required key "Task[completed]" has a null value in JSON.');
assert(json.containsKey(r'priority'), 'Required key "Task[priority]" is missing from JSON.');
assert(json[r'priority'] != null, 'Required key "Task[priority]" has a null value in JSON.');
assert(json.containsKey(r'createdAt'), 'Required key "Task[createdAt]" is missing from JSON.');
assert(json[r'createdAt'] != null, 'Required key "Task[createdAt]" has a null value in JSON.');
assert(json.containsKey(r'updatedAt'), 'Required key "Task[updatedAt]" is missing from JSON.');
assert(json[r'updatedAt'] != null, 'Required key "Task[updatedAt]" has a null value in JSON.');
return true;
}());
return Task(
id: mapValueOfType<String>(json, r'id')!,
provider: mapValueOfType<String>(json, r'provider'),
accountId: mapValueOfType<String>(json, r'accountId'),
ownerUserId: mapValueOfType<String>(json, r'ownerUserId'),
title: mapValueOfType<String>(json, r'title')!,
description: mapValueOfType<String>(json, r'description'),
status: mapValueOfType<String>(json, r'status'),
completed: mapValueOfType<bool>(json, r'completed')!,
dueDate: mapDateTime(json, r'dueDate', r''),
priority: TaskPriorityEnum.fromJson(json[r'priority'])!,
labels: json[r'labels'] is Iterable
? (json[r'labels'] as Iterable).cast<String>().toList(growable: false)
: const [],
tags: json[r'tags'] is Iterable
? (json[r'tags'] as Iterable).cast<String>().toList(growable: false)
: const [],
assigneeId: mapValueOfType<String>(json, r'assigneeId'),
createdAt: mapDateTime(json, r'createdAt', r'')!,
updatedAt: mapDateTime(json, r'updatedAt', r'')!,
completedAt: mapDateTime(json, r'completedAt', r''),
parentTaskId: mapValueOfType<String>(json, r'parentTaskId'),
metadata: mapCastOfType<String, Object>(json, r'metadata') ?? const {},
type: mapValueOfType<String>(json, r'type'),
sourcePlatform: mapValueOfType<String>(json, r'sourcePlatform'),
sourceId: mapValueOfType<String>(json, r'sourceId'),
);
}
return null;
}