void createServiceGroups() {
List<String> serviceGroups = [];
serviceGroups.addAll([
'Select your Service Group',
'Cleaning, Laundry & Maid Services',
'Movers / Relocators',
'Electronics & Gadget',
'Home Improvement & Maintenance',
'Beauty, Wellness & Nutrition',
'Weddings',
'Food & Beverage',
'Style & Apparel',
'Events & Entertainment',
'Photographer & Videographers',
'Health & Fitness',
'Car Repairs & Maintenance',
'Professional & Business Services',
'Language Lessons',
'Professional & Hobby Lessons',
'Academic Lessons',
]);
Firestore db = Firestore.instance;
// DocumentReference ref = db
// .collection("service_groups")
// .document(Random().nextInt(10000).toString());
// print(ref.documentID);
// Get a new write batch
for (var serviceGroup in serviceGroups) {
createDocument(db, "name", serviceGroup);
}
print("length ${serviceGroups.length}");
}
createDocument(Firestore db, String k, String v) {
WriteBatch batch = db.batch();
batch.setData(db.collection("service_groups").document(), {k: v});
batch.commit();
}
createDocument(Firestore db, String k, String v) {
WriteBatch batch = db.batch();
batch.setData(db.collection("service_groups").document(), {k: v});
batch.commit();
}
这可能会帮助您:
for (var serviceGroup in serviceGroups) {
createDocument(db, "name", serviceGroup );
}