fromJson static method
Returns a new SubscriptionSchema instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static SubscriptionSchema? 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'plan'),
'Required key "SubscriptionSchema[plan]" is missing from JSON.');
assert(json[r'plan'] != null,
'Required key "SubscriptionSchema[plan]" has a null value in JSON.');
assert(json.containsKey(r'purchase_source'),
'Required key "SubscriptionSchema[purchase_source]" is missing from JSON.');
assert(json[r'purchase_source'] != null,
'Required key "SubscriptionSchema[purchase_source]" has a null value in JSON.');
assert(json.containsKey(r'status'),
'Required key "SubscriptionSchema[status]" is missing from JSON.');
assert(json[r'status'] != null,
'Required key "SubscriptionSchema[status]" has a null value in JSON.');
assert(json.containsKey(r'current_period_start'),
'Required key "SubscriptionSchema[current_period_start]" is missing from JSON.');
assert(json[r'current_period_start'] != null,
'Required key "SubscriptionSchema[current_period_start]" has a null value in JSON.');
assert(json.containsKey(r'current_period_end'),
'Required key "SubscriptionSchema[current_period_end]" is missing from JSON.');
assert(json[r'current_period_end'] != null,
'Required key "SubscriptionSchema[current_period_end]" has a null value in JSON.');
assert(json.containsKey(r'created_at'),
'Required key "SubscriptionSchema[created_at]" is missing from JSON.');
assert(json[r'created_at'] != null,
'Required key "SubscriptionSchema[created_at]" has a null value in JSON.');
return true;
}());
return SubscriptionSchema(
plan: SubscriptionPlan.fromJson(json[r'plan'])!,
purchaseSource: SubscriptionSchemaPurchaseSourceEnum.fromJson(
json[r'purchase_source'])!,
status: mapValueOfType<String>(json, r'status')!,
currentPeriodStart: mapDateTime(json, r'current_period_start', r'')!,
currentPeriodEnd: mapDateTime(json, r'current_period_end', r'')!,
createdAt: mapDateTime(json, r'created_at', r'')!,
cancelledAt: mapDateTime(json, r'cancelled_at', r''),
);
}
return null;
}