fromJson static method
Tax?
fromJson(
- dynamic value
)
Returns a new Tax instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Tax? 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'name'), 'Required key "Tax[name]" is missing from JSON.');
assert(json[r'name'] != null, 'Required key "Tax[name]" has a null value in JSON.');
assert(json.containsKey(r'amount'), 'Required key "Tax[amount]" is missing from JSON.');
assert(json[r'amount'] != null, 'Required key "Tax[amount]" has a null value in JSON.');
return true;
}());
return Tax(
name: mapValueOfType<String>(json, r'name')!,
amount: num.parse('${json[r'amount']}'),
currency: mapValueOfType<String>(json, r'currency'),
includedInPrice: mapValueOfType<bool>(json, r'includedInPrice'),
);
}
return null;
}