addOrUpdateFirestore function
Implementation
Future<void> addOrUpdateFirestore(Product product) async {
final collection = Firestore.instance.collection("inventory");
final querySnapshot = await collection
.where("name", isEqualTo: product.name)
.get();
if (querySnapshot.isEmpty) {
await collection.add(product.toFirestore());
} else {
await Future.wait(
querySnapshot.map(
(doc) => collection.document(doc.id).update(product.toFirestore()),
),
);
}
}