all method

  1. @override
Future<void> all(
  1. Type type, {
  2. required bool iAmSure,
  3. String? subcollection,
})
override

Deletes all documents of a specific type from Firestore.

Implementation

@override
Future<void> all(Type type, { required bool iAmSure, String? subcollection }) async {
  if (iAmSure) {
    Map<String, dynamic>? snapshot;
    if (subcollection == null) {
      snapshot = await LS.instance.collection(type.toString()).get();
    }
    else {
      snapshot =
      await LS.instance.collection(type.toString()).doc(subcollection)
          .collection(subcollection)
          .get();
    }
    if (snapshot == null) return Future.value();
    if (snapshot.isEmpty) return Future.value();

    List<Future> futures = [];
    for (var entry in snapshot.entries) {
      futures.add(LS.instance.collection(type.toString()).doc(entry.key.split("/")[2]).delete());
    }

    await Future.wait(futures);
  }
}