ClimateProduct.fromJson constructor

ClimateProduct.fromJson(
  1. Object? json
)

Implementation

factory ClimateProduct.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return ClimateProduct(
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    currentPricesPerMetricTon: (map['current_prices_per_metric_ton'] as Map)
        .cast<String, Object?>()
        .map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              ClimateRemovalsProductsPrice.fromJson(value),
            )),
    deliveryYear: map['delivery_year'] == null
        ? null
        : (map['delivery_year'] as num).toInt(),
    id: (map['id'] as String),
    livemode: (map['livemode'] as bool),
    metricTonsAvailable: (map['metric_tons_available'] as String),
    name: (map['name'] as String),
    suppliers: (map['suppliers'] as List<Object?>)
        .map((el) => ClimateSupplier.fromJson(el))
        .toList(),
  );
}