fromJson static method
Returns a new SchemasCommercePlan instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static SchemasCommercePlan? 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 "SchemasCommercePlan[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "SchemasCommercePlan[$key]" has a null value in JSON.');
});
return true;
}());
return SchemasCommercePlan(
object: SchemasCommercePlanObjectEnum.fromJson(json[r'object'])!,
id: mapValueOfType<String>(json, r'id')!,
name: mapValueOfType<String>(json, r'name')!,
fee: CommerceMoneyResponse.fromJson(json[r'fee'])!,
annualMonthlyFee:
CommerceMoneyResponse.fromJson(json[r'annual_monthly_fee'])!,
annualFee: CommerceMoneyResponse.fromJson(json[r'annual_fee'])!,
amount: mapValueOfType<int>(json, r'amount')!,
amountFormatted: mapValueOfType<String>(json, r'amount_formatted')!,
annualMonthlyAmount:
mapValueOfType<int>(json, r'annual_monthly_amount')!,
annualMonthlyAmountFormatted:
mapValueOfType<String>(json, r'annual_monthly_amount_formatted')!,
annualAmount: mapValueOfType<int>(json, r'annual_amount')!,
annualAmountFormatted:
mapValueOfType<String>(json, r'annual_amount_formatted')!,
currencySymbol: mapValueOfType<String>(json, r'currency_symbol')!,
currency: mapValueOfType<String>(json, r'currency')!,
description: mapValueOfType<String>(json, r'description')!,
productId: mapValueOfType<String>(json, r'product_id')!,
isDefault: mapValueOfType<bool>(json, r'is_default')!,
isRecurring: mapValueOfType<bool>(json, r'is_recurring')!,
publiclyVisible: mapValueOfType<bool>(json, r'publicly_visible')!,
hasBaseFee: mapValueOfType<bool>(json, r'has_base_fee')!,
payerType: json[r'payer_type'] is Iterable
? (json[r'payer_type'] as Iterable)
.cast<String>()
.toList(growable: false)
: const [],
forPayerType: mapValueOfType<String>(json, r'for_payer_type')!,
slug: mapValueOfType<String>(json, r'slug')!,
avatarUrl: mapValueOfType<String>(json, r'avatar_url')!,
period: mapValueOfType<String>(json, r'period'),
interval: mapValueOfType<int>(json, r'interval'),
features: SchemasFeatureResponse.listFromJson(json[r'features']),
freeTrialEnabled: mapValueOfType<bool>(json, r'free_trial_enabled'),
freeTrialDays: mapValueOfType<int>(json, r'free_trial_days'),
);
}
return null;
}