CheckoutLineItem.fromJson constructor

CheckoutLineItem.fromJson(
  1. Map<Object?, Object?> value
)

Parses and validates a line item from the native bridge.

Implementation

factory CheckoutLineItem.fromJson(Map<Object?, Object?> value) {
  _expectFields(value, const {'id', 'name', 'quantity', 'total'});
  final id = value['id'];
  final name = value['name'];
  final quantity = value['quantity'];
  final total = value['total'];
  if (id is! String ||
      id.isEmpty ||
      name is! String ||
      name.isEmpty ||
      (quantity != null && (quantity is! int || quantity < 0)) ||
      total is! Map) {
    throw const FormatException('Invalid Checkout line item');
  }
  return CheckoutLineItem(
    id: id,
    name: name,
    quantity: quantity as int?,
    total: CheckoutMoney.fromJson(Map<Object?, Object?>.from(total)),
  );
}