Product.fromJson constructor

Product.fromJson(
  1. Object? json
)

Implementation

factory Product.fromJson(Object? json) {
  final map = (json as Map).cast<String, Object?>();
  return Product(
    active: (map['active'] as bool),
    created:
        DateTime.fromMillisecondsSinceEpoch((map['created'] as int).toInt()),
    defaultPrice: map['default_price'] == null
        ? null
        : PriceOrId.fromJson(map['default_price']),
    description:
        map['description'] == null ? null : (map['description'] as String),
    features: (map['features'] as List<Object?>)
        .map((el) => ProductMarketingFeature.fromJson(el))
        .toList(),
    id: (map['id'] as String),
    images:
        (map['images'] as List<Object?>).map((el) => (el as String)).toList(),
    livemode: (map['livemode'] as bool),
    metadata: (map['metadata'] as Map).cast<String, Object?>().map((
          key,
          value,
        ) =>
            MapEntry(
              key,
              (value as String),
            )),
    name: (map['name'] as String),
    packageDimensions: map['package_dimensions'] == null
        ? null
        : PackageDimensions.fromJson(map['package_dimensions']),
    shippable: map['shippable'] == null ? null : (map['shippable'] as bool),
    statementDescriptor: map['statement_descriptor'] == null
        ? null
        : (map['statement_descriptor'] as String),
    taxCode: map['tax_code'] == null
        ? null
        : TaxCodeOrId.fromJson(map['tax_code']),
    type: ProductType.fromJson(map['type']),
    unitLabel:
        map['unit_label'] == null ? null : (map['unit_label'] as String),
    updated:
        DateTime.fromMillisecondsSinceEpoch((map['updated'] as int).toInt()),
    url: map['url'] == null ? null : (map['url'] as String),
  );
}