fromMap static method

ProductEntity? fromMap(
  1. Object? o, {
  2. Map<String, String>? newDocumentIds,
})

Implementation

static ProductEntity? fromMap(Object? o,
    {Map<String, String>? newDocumentIds}) {
  if (o == null) return null;
  var map = o as Map<String, dynamic>;

  var imagesFromMap = map['images'];
  List<ProductImageEntity> imagesList;
  if (imagesFromMap != null) {
    imagesList = (map['images'] as List<dynamic>)
        .map((dynamic item) => ProductImageEntity.fromMap(item as Map,
            newDocumentIds: newDocumentIds)!)
        .toList();
  } else {
    imagesList = [];
  }
  var posSizeFromMap = map['posSize'];
  if (posSizeFromMap != null) {
    posSizeFromMap =
        PosSizeEntity.fromMap(posSizeFromMap, newDocumentIds: newDocumentIds);
  }

  return ProductEntity(
    appId: map['appId'],
    title: map['title'],
    about: map['about'],
    price: double.tryParse(map['price'].toString()),
    weight: double.tryParse(map['weight'].toString()),
    shopId: map['shopId'],
    images: imagesList,
    posSize: posSizeFromMap,
  );
}