fromJson static method
Returns a new Envelope instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Envelope? 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'data'), 'Required key "Envelope[data]" is missing from JSON.');
assert(json.containsKey(r'cost'), 'Required key "Envelope[cost]" is missing from JSON.');
assert(json[r'cost'] != null, 'Required key "Envelope[cost]" has a null value in JSON.');
assert(json.containsKey(r'credits_remaining'), 'Required key "Envelope[credits_remaining]" is missing from JSON.');
assert(json[r'credits_remaining'] != null, 'Required key "Envelope[credits_remaining]" has a null value in JSON.');
assert(json.containsKey(r'rate_limit_limit'), 'Required key "Envelope[rate_limit_limit]" is missing from JSON.');
assert(json[r'rate_limit_limit'] != null, 'Required key "Envelope[rate_limit_limit]" has a null value in JSON.');
assert(json.containsKey(r'rate_limit_remaining'), 'Required key "Envelope[rate_limit_remaining]" is missing from JSON.');
assert(json[r'rate_limit_remaining'] != null, 'Required key "Envelope[rate_limit_remaining]" has a null value in JSON.');
assert(json.containsKey(r'rate_limit_reset'), 'Required key "Envelope[rate_limit_reset]" is missing from JSON.');
assert(json[r'rate_limit_reset'] != null, 'Required key "Envelope[rate_limit_reset]" has a null value in JSON.');
assert(json.containsKey(r'metering'), 'Required key "Envelope[metering]" is missing from JSON.');
assert(json[r'metering'] != null, 'Required key "Envelope[metering]" has a null value in JSON.');
assert(json.containsKey(r'request_id'), 'Required key "Envelope[request_id]" is missing from JSON.');
assert(json[r'request_id'] != null, 'Required key "Envelope[request_id]" has a null value in JSON.');
return true;
}());
return Envelope(
data: mapValueOfType<Object>(json, r'data'),
cost: mapValueOfType<int>(json, r'cost')!,
creditsRemaining: mapValueOfType<int>(json, r'credits_remaining')!,
rateLimitLimit: mapValueOfType<int>(json, r'rate_limit_limit')!,
rateLimitRemaining: mapValueOfType<int>(json, r'rate_limit_remaining')!,
rateLimitReset: mapValueOfType<int>(json, r'rate_limit_reset')!,
metering: EnvelopeMeteringEnum.fromJson(json[r'metering'])!,
requestId: mapValueOfType<String>(json, r'request_id')!,
);
}
return null;
}