I'm trying to delete document in firestore with this function,
[UPDATE] following code from the documentation
class DatabaseService {
final String uid;
final String taskId;
final String boardId;
DatabaseService({this.uid, this.taskId, this.boardId});
///delete task
Future<void> deleteTask() async {
return await FirebaseFirestore.instance
.collection('user')
.doc(uid)
.collection('tasks')
.doc(taskId)
.delete()
.then((value) => print('task $taskId deleted'))
.catchError((error) => print("Failed to delete task: $error"));
}
}
I put wrong collection name, supposedly tasks. I already update with the right name.
trigger button:
IconButton(
icon: Icon(
Icons.delete_outline,
color: kColorRed,
),
onPressed: () async {
print('task delete pressed');
print(widget.userId);
print(widget.taskId);
await DatabaseService(uid: widget.userId, taskId: widget.taskId)
.deleteTask();
Navigator.pop(context);
}),
output:
flutter: task delete pressed
flutter: VWtHv8LPE3brezl9a5zmHlwYM5h2
flutter: [#9bb27]
flutter: VWtHv8LPE3brezl9a5zmHlwYM5h2 task [#9bb27] deleted
inside the document:

it back with the print result. But, when I checked on Firestore, the document still there. Am I doing it right?