fromJson static method
Model?
fromJson(
- dynamic value
)
Returns a new Model instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Model? 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 "Model[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "Model[$key]" has a null value in JSON.');
});
return true;
}());
return Model(
id: mapValueOfType<String>(json, r'id')!,
project: mapValueOfType<String>(json, r'project')!,
name: mapValueOfType<String>(json, r'name')!,
nameDe: mapValueOfType<String>(json, r'name_de'),
nameEn: mapValueOfType<String>(json, r'name_en'),
nameFr: mapValueOfType<String>(json, r'name_fr'),
nameIt: mapValueOfType<String>(json, r'name_it'),
slug: mapValueOfType<String>(json, r'slug'),
image: mapValueOfType<String>(json, r'image'),
imageThumb: mapValueOfType<String>(json, r'image_thumb') ?? '',
imagePreview: mapValueOfType<String>(json, r'image_preview') ?? '',
preview: mapValueOfType<bool>(json, r'preview'),
status: ModelStatus.fromJson(json[r'status']),
description: mapValueOfType<String>(json, r'description') ?? '',
descriptionDe: mapValueOfType<String>(json, r'description_de'),
descriptionEn: mapValueOfType<String>(json, r'description_en'),
descriptionFr: mapValueOfType<String>(json, r'description_fr'),
descriptionIt: mapValueOfType<String>(json, r'description_it'),
number: mapValueOfType<int>(json, r'number'),
siteUrl: mapValueOfType<String>(json, r'site_url') ?? '',
siteUrlDe: mapValueOfType<String>(json, r'site_url_de'),
siteUrlEn: mapValueOfType<String>(json, r'site_url_en'),
siteUrlFr: mapValueOfType<String>(json, r'site_url_fr'),
siteUrlIt: mapValueOfType<String>(json, r'site_url_it'),
sku: mapValueOfType<String>(json, r'sku'),
price: mapValueOfType<double>(json, r'price'),
priceCurrency: mapValueOfType<String>(json, r'price_currency') ?? 'CHF',
scaleable: mapValueOfType<bool>(json, r'scaleable'),
glb: mapValueOfType<String>(json, r'glb'),
usdz: mapValueOfType<String>(json, r'usdz'),
model: mapValueOfType<String>(json, r'model'),
arbuttonConfig: mapCastOfType<String, Object>(json, r'arbutton_config') ?? const {},
created: mapDateTime(json, r'created', r'')!,
modified: mapDateTime(json, r'modified', r'')!,
verticalPlacement: mapValueOfType<bool>(json, r'vertical_placement'),
);
}
return null;
}