fromJson static method
Returns a new MmSlackAttachment instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static MmSlackAttachment? 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(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key), 'Required key "MmSlackAttachment[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "MmSlackAttachment[$key]" has a null value in JSON.');
});
return true;
}());
return MmSlackAttachment(
id: mapValueOfType<String>(json, r'Id'),
fallback: mapValueOfType<String>(json, r'Fallback'),
color: mapValueOfType<String>(json, r'Color'),
pretext: mapValueOfType<String>(json, r'Pretext'),
authorName: mapValueOfType<String>(json, r'AuthorName'),
authorLink: mapValueOfType<String>(json, r'AuthorLink'),
authorIcon: mapValueOfType<String>(json, r'AuthorIcon'),
title: mapValueOfType<String>(json, r'Title'),
titleLink: mapValueOfType<String>(json, r'TitleLink'),
text: mapValueOfType<String>(json, r'Text'),
fields: MmSlackAttachmentField.listFromJson(json[r'Fields']) ?? const [],
imageURL: mapValueOfType<String>(json, r'ImageURL'),
thumbURL: mapValueOfType<String>(json, r'ThumbURL'),
footer: mapValueOfType<String>(json, r'Footer'),
footerIcon: mapValueOfType<String>(json, r'FooterIcon'),
timestamp: mapValueOfType<String>(json, r'Timestamp'),
);
}
return null;
}