initFirestoreCollection function

Future<void> initFirestoreCollection()

Implementation

Future<void> initFirestoreCollection() async {
  final random = Random();
  final oldProducts = [
    "Apples",
    "Bananas",
    "Milk",
    "Whole Wheat Bread",
    "Eggs",
    "Cheddar Cheese",
    "Whole Chicken",
    "Rice",
    "Black Beans",
    "Bottled Water",
    "Apple Juice",
    "Cola",
    "Coffee Beans",
    "Green Tea",
    "Watermelon",
    "Broccoli",
    "Jasmine Rice",
    "Yogurt",
    "Beef",
    "Shrimp",
    "Walnuts",
    "Sunflower Seeds",
    "Fresh Basil",
    "Cinnamon",
  ];

  final futures = <Future>[];

  for (final productName in oldProducts) {
    final product = Product(
      name: productName,
      price: (random.nextInt(10) + 1).toDouble(),
      quantity: random.nextInt(500) + 1,
      imgfile:
          "product-images/${productName.replaceAll(' ', '').toLowerCase()}.png",
      timestamp: DateTime.now().subtract(
        Duration(
          milliseconds:
              (random.nextDouble() * 31536000000).toInt() + 7776000000,
        ),
      ),
      actualdateadded: DateTime.now(),
    );
    futures.add(addOrUpdateFirestore(product));
  }

  final recentProducts = [
    "Parmesan Crisps",
    "Pineapple Kombucha",
    "Maple Almond Butter",
    "Mint Chocolate Cookies",
    "White Chocolate Caramel Corn",
    "Acai Smoothie Packs",
    "Smores Cereal",
    "Peanut Butter and Jelly Cups",
  ];

  for (final productName in recentProducts) {
    final product = Product(
      name: productName,
      price: (random.nextInt(10) + 1).toDouble(),
      quantity: random.nextInt(100) + 1,
      imgfile:
          "product-images/${productName.replaceAll(' ', '').toLowerCase()}.png",
      timestamp: DateTime.now().subtract(
        Duration(milliseconds: (random.nextDouble() * 518400000).toInt() + 1),
      ),
      actualdateadded: DateTime.now(),
    );
    futures.add(addOrUpdateFirestore(product));
  }

  final recentProductsOutOfStock = ["Wasabi Party Mix", "Jalapeno Seasoning"];
  for (final productName in recentProductsOutOfStock) {
    final product = Product(
      name: productName,
      price: (random.nextInt(10) + 1).toDouble(),
      quantity: 0,
      imgfile:
          "product-images/${productName.replaceAll(' ', '').toLowerCase()}.png",
      timestamp: DateTime.now().subtract(
        Duration(milliseconds: (random.nextDouble() * 518400000).toInt() + 1),
      ),
      actualdateadded: DateTime.now(),
    );
    futures.add(addOrUpdateFirestore(product));
  }

  await Future.wait(futures);
}