ClimateOrder.fromJson constructor

ClimateOrder.fromJson(
  1. Object? json
)

Implementation

factory ClimateOrder.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return ClimateOrder(
    amountFees: (map['amount_fees'] as num).toInt(),
    amountSubtotal: (map['amount_subtotal'] as num).toInt(),
    amountTotal: (map['amount_total'] as num).toInt(),
    beneficiary: map['beneficiary'] == null
        ? null
        : ClimateRemovalsBeneficiary.fromJson(map['beneficiary']),
    canceledAt: map['canceled_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['canceled_at'] as int).toInt()),
    cancellationReason: map['cancellation_reason'] == null
        ? null
        : ClimateOrderCancellationReason.fromJson(map['cancellation_reason']),
    certificate:
        map['certificate'] == null ? null : (map['certificate'] as String),
    confirmedAt: map['confirmed_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['confirmed_at'] as int).toInt()),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    currency: (map['currency'] as String),
    delayedAt: map['delayed_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['delayed_at'] as int).toInt()),
    deliveredAt: map['delivered_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['delivered_at'] as int).toInt()),
    deliveryDetails: (map['delivery_details'] as List<Object?>)
        .map((el) => ClimateRemovalsOrderDeliveries.fromJson(el))
        .toList(),
    expectedDeliveryYear: (map['expected_delivery_year'] as num).toInt(),
    id: (map['id'] as String),
    livemode: (map['livemode'] as bool),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    metricTons: (map['metric_tons'] as String),
    product: ClimateProductOrId.fromJson(map['product']),
    productSubstitutedAt: map['product_substituted_at'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['product_substituted_at'] as int).toInt()),
    status: ClimateOrderStatus.fromJson(map['status']),
  );
}