'Flutter & MongoDb Error: 'The method '[]' was called on null. Receiver: null Tried calling: []("id"))'

I am new to coding. I was following the course and I get an error that I don't know how to solve.

I want to create a user and then I want to create a task associated with this user. Both, the user and the task get created - I can see it in mongodb. Somehow the userid for this newly created task ends up being null and I get 'The method '[]' was called on null. Receiver: null Tried calling: )' error. Again, user id is created - I can see it in mongodb. I suspect something is wrong with the way I try to retrieve userId

This is how I retrieve the userId:

child: Mutation(
                  options: MutationOptions(
                    document: gql(insertTask()),
                    fetchPolicy: FetchPolicy.noCache,
                    onCompleted: (data) {
                      print(data.toString());
                      setState(() {
                        _isSaving = false;
                        currUserId = data['createUser']["id"];
                      });
                    },
                  ),

Please advise, I suspect it may be something silly, but I can't get my head around it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source