fromJson static method

Card? fromJson(
  1. dynamic value
)

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

Implementation

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

    return Card(
      id: mapValueOfType<int>(json, r'id'),
      created: mapDateTime(json, r'created', r''),
      modified: mapDateTime(json, r'modified', r''),
      deletedAt: mapDateTime(json, r'deleted_at', r''),
      stripeToken: mapValueOfType<String>(json, r'stripe_token')!,
      stripeId: mapValueOfType<String>(json, r'stripe_id'),
      last4: mapValueOfType<String>(json, r'last4'),
      brand: mapValueOfType<String>(json, r'brand'),
      country: mapValueOfType<String>(json, r'country'),
      expMonth: mapValueOfType<int>(json, r'exp_month'),
      expYear: mapValueOfType<int>(json, r'exp_year'),
      isDefault: mapValueOfType<bool>(json, r'is_default'),
      isActive: mapValueOfType<bool>(json, r'is_active'),
      user: mapValueOfType<int>(json, r'user')!,
    );
  }
  return null;
}