Product.fromMap constructor

Product.fromMap(
  1. Map<String, dynamic> map,
  2. String id
)

Creates a Product from a Firestore document map.

Parameters:

  • map: A Map<String, dynamic> containing the product's data.
  • id: The unique identifier of the product.

Returns: A Product instance populated with the map's data.

Implementation

factory Product.fromMap(Map<String, dynamic> map, String id) {
  return Product(
    id: id,
    name: map['name'],
    description: map['description'],
    price: map['price'].toDouble(),
    unit: map['unit'],
    quantity: map['quantity'],
    farmerId: map['farmerId'],
    imageUrls: List<String>.from(map['imageUrls']),
    dateAdded: DateTime.parse(map['dateAdded']),
    category: map['category'],
  );
}