fromJson static method
Block?
fromJson(
- dynamic value
)
Returns a new Block instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Block? 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 "Block[id]" is missing from JSON.');
assert(json[r'id'] != null, 'Required key "Block[id]" has a null value in JSON.');
assert(json.containsKey(r'noteId'), 'Required key "Block[noteId]" is missing from JSON.');
assert(json[r'noteId'] != null, 'Required key "Block[noteId]" has a null value in JSON.');
assert(json.containsKey(r'type'), 'Required key "Block[type]" is missing from JSON.');
assert(json[r'type'] != null, 'Required key "Block[type]" has a null value in JSON.');
assert(json.containsKey(r'content'), 'Required key "Block[content]" is missing from JSON.');
assert(json[r'content'] != null, 'Required key "Block[content]" has a null value in JSON.');
assert(json.containsKey(r'position'), 'Required key "Block[position]" is missing from JSON.');
assert(json[r'position'] != null, 'Required key "Block[position]" has a null value in JSON.');
assert(json.containsKey(r'hasChildren'), 'Required key "Block[hasChildren]" is missing from JSON.');
assert(json[r'hasChildren'] != null, 'Required key "Block[hasChildren]" has a null value in JSON.');
assert(json.containsKey(r'createdAt'), 'Required key "Block[createdAt]" is missing from JSON.');
assert(json[r'createdAt'] != null, 'Required key "Block[createdAt]" has a null value in JSON.');
assert(json.containsKey(r'updatedAt'), 'Required key "Block[updatedAt]" is missing from JSON.');
assert(json[r'updatedAt'] != null, 'Required key "Block[updatedAt]" has a null value in JSON.');
return true;
}());
return Block(
id: mapValueOfType<String>(json, r'id')!,
noteId: mapValueOfType<String>(json, r'noteId')!,
parentId: mapValueOfType<String>(json, r'parentId'),
type: BlockType.fromJson(json[r'type'])!,
content: BlockContent.fromJson(json[r'content'])!,
properties: mapCastOfType<String, Object>(json, r'properties') ?? const {},
position: mapValueOfType<int>(json, r'position')!,
hasChildren: mapValueOfType<bool>(json, r'hasChildren')!,
createdAt: mapDateTime(json, r'createdAt', r'')!,
updatedAt: mapDateTime(json, r'updatedAt', r'')!,
);
}
return null;
}