fromJson static method

GEOrderHistorySchema? fromJson(
  1. dynamic value
)

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

Implementation

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

    return GEOrderHistorySchema(
      orderId: mapValueOfType<String>(json, r'order_id')!,
      seller: mapValueOfType<String>(json, r'seller')!,
      buyer: mapValueOfType<String>(json, r'buyer')!,
      code: mapValueOfType<String>(json, r'code')!,
      quantity: mapValueOfType<int>(json, r'quantity')!,
      price: mapValueOfType<int>(json, r'price')!,
      soldAt: mapDateTime(json, r'sold_at', r'')!,
    );
  }
  return null;
}