fromJson static method
Returns a new Template instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Template? 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 "Template[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "Template[$key]" has a null value in JSON.');
});
return true;
}());
return Template(
id: mapValueOfType<String>(json, r'id'),
object: TemplateObjectEnum.fromJson(json[r'object']),
instanceId: mapValueOfType<String>(json, r'instance_id'),
resourceType: mapValueOfType<String>(json, r'resource_type'),
templateType: mapValueOfType<String>(json, r'template_type'),
name: mapValueOfType<String>(json, r'name'),
slug: mapValueOfType<String>(json, r'slug'),
position: mapValueOfType<int>(json, r'position'),
canRevert: mapValueOfType<bool>(json, r'can_revert'),
canDelete: mapValueOfType<bool>(json, r'can_delete'),
canToggle: mapValueOfType<bool>(json, r'can_toggle'),
subject: mapValueOfType<String>(json, r'subject'),
markup: mapValueOfType<String>(json, r'markup'),
body: mapValueOfType<String>(json, r'body'),
availableVariables: json[r'available_variables'] is Iterable
? (json[r'available_variables'] as Iterable)
.cast<String>()
.toList(growable: false)
: const [],
requiredVariables: json[r'required_variables'] is Iterable
? (json[r'required_variables'] as Iterable)
.cast<String>()
.toList(growable: false)
: const [],
fromEmailName: mapValueOfType<String>(json, r'from_email_name'),
replyToEmailName: mapValueOfType<String>(json, r'reply_to_email_name'),
deliveredByClerk: mapValueOfType<bool>(json, r'delivered_by_clerk'),
enabled: mapValueOfType<bool>(json, r'enabled'),
updatedAt: mapValueOfType<int>(json, r'updated_at'),
createdAt: mapValueOfType<int>(json, r'created_at'),
);
}
return null;
}