'Firebase request in Flutter avoids then block

I am trying to recieve the username of the currently logged in user from firebase, to show the name in the appbar. I am currently doing this with a FutureBuilder, which got the following method as future:

 _getUser() async {
        print("we are inside!!!");
        await FirebaseFirestore.instance
            .collection('users')
            .where("user_id", isEqualTo: FirebaseAuth.instance.currentUser!.uid)
            .snapshots()
            .first
            .then((QuerySnapshot querySnapshot) {
          querySnapshot.docs.forEach((doc) {
            this._userName = doc["user_name"];
            print("we found username: " + _userName);
          });
        });
        await Future.delayed(Duration(seconds: 1));
        print("i bims hier rein");
        return this._memoizer.runOnce(() async {
          return _userName;
        });
      }

That worked perfectly fine until now: I added some kind of tutorial for new users (package: tutorial_coach_mark). When a new user logged in the tutorial shows up and after the tutorial the app starts, but the name of the user isn't recieved by the method shown above.

When the user is a old user and the tutorial does not show, the name is recieved.

Thanks in advance!



Sources

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

Source: Stack Overflow

Solution Source