fromJson static method

CommercePlan? fromJson(
  1. dynamic value
)

Returns a new CommercePlan instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static CommercePlan? 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 "CommercePlan[$key]" is missing from JSON.');
        assert(json[key] != null,
            'Required key "CommercePlan[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return CommercePlan(
      object: CommercePlanObjectEnum.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']),
      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')!,
      forPayerType: mapValueOfType<String>(json, r'for_payer_type')!,
      slug: mapValueOfType<String>(json, r'slug')!,
      avatarUrl: mapValueOfType<String>(json, r'avatar_url'),
      features: FeatureResponse.listFromJson(json[r'features']),
      freeTrialEnabled: mapValueOfType<bool>(json, r'free_trial_enabled')!,
      freeTrialDays: mapValueOfType<int>(json, r'free_trial_days'),
    );
  }
  return null;
}