fromJson static method

GETransactionSchema? fromJson(
  1. dynamic value
)

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

Implementation

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

    return GETransactionSchema(
      id: mapValueOfType<String>(json, r'id')!,
      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;
}