Flutter document Firestore is not deleting [CLOSE]

Viewed 394

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"));
      }
}

enter image description here 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:

enter image description here

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

1 Answers

I got the same problem .

I have solve this by check userid is passing or not .I mean getting the value for userid

Related