fromJson static method

GEOrderCreatedSchema? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static GEOrderCreatedSchema? 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'id'),
          'Required key "GEOrderCreatedSchema[id]" is missing from JSON.');
      assert(json[r'id'] != null,
          'Required key "GEOrderCreatedSchema[id]" has a null value in JSON.');
      assert(json.containsKey(r'created_at'),
          'Required key "GEOrderCreatedSchema[created_at]" is missing from JSON.');
      assert(json[r'created_at'] != null,
          'Required key "GEOrderCreatedSchema[created_at]" has a null value in JSON.');
      assert(json.containsKey(r'code'),
          'Required key "GEOrderCreatedSchema[code]" is missing from JSON.');
      assert(json[r'code'] != null,
          'Required key "GEOrderCreatedSchema[code]" has a null value in JSON.');
      assert(json.containsKey(r'quantity'),
          'Required key "GEOrderCreatedSchema[quantity]" is missing from JSON.');
      assert(json[r'quantity'] != null,
          'Required key "GEOrderCreatedSchema[quantity]" has a null value in JSON.');
      assert(json.containsKey(r'price'),
          'Required key "GEOrderCreatedSchema[price]" is missing from JSON.');
      assert(json[r'price'] != null,
          'Required key "GEOrderCreatedSchema[price]" has a null value in JSON.');
      assert(json.containsKey(r'total_price'),
          'Required key "GEOrderCreatedSchema[total_price]" is missing from JSON.');
      assert(json[r'total_price'] != null,
          'Required key "GEOrderCreatedSchema[total_price]" has a null value in JSON.');
      return true;
    }());

    return GEOrderCreatedSchema(
      id: mapValueOfType<String>(json, r'id')!,
      createdAt: mapDateTime(json, r'created_at', r'')!,
      code: mapValueOfType<String>(json, r'code')!,
      quantity: mapValueOfType<int>(json, r'quantity')!,
      price: mapValueOfType<int>(json, r'price')!,
      totalPrice: mapValueOfType<int>(json, r'total_price')!,
    );
  }
  return null;
}