delete method

Future<void> delete()

Delete a field to a doc of task Delete task including all the related assigns and data.

Implementation

// Future<void> deleteField(List<String> fields) async {
//   final deleteData = Map<String, dynamic>.fromEntries(
//     fields.map((field) => MapEntry(field, FieldValue.delete())),
//   );
//   await ref.update(deleteData);
// }

/// Delete task including all the related assigns and data.
Future<void> delete() async {
  final assigns = await TodoService.instance.assignCol
      .where('taskId', isEqualTo: id)
      .get();

  // Delete the assigns under the task first
  final assignDeleteFutures =
      assigns.docs.map((assign) => assign.reference.delete());

  // Await for all the assign delete futures
  await Future.wait(assignDeleteFutures);

  // Delete the task if all the assigns are deleted
  await ref.delete();
}