delete method

dynamic delete(
  1. dynamic field,
  2. dynamic value
)

Implementation

delete(field, value) {
  if (field == null && value == null) {
    throw Exception('Field $field not found');
  } else if (fields.where((element) => element.field == field).isEmpty) {
    throw Exception('Field $field not found');
  }
  database().where(field, isEqualTo: value).get().then((value) {
    for (var element in value.docs) {
      element.reference.delete();
    }
  });
  firestore.collection('Xactivity').add({
    'activity': 'Deleted $className',
    'time': DateTime.now(),
    'by' : FirebaseAuth.instance.currentUser!.email,
  });
}