Chorche
Chorche

Reputation: 85

Cannot return user data in UserAccountsDrawerHeader with FirebaseStore/Flutter

I am having an issue with returning user's email in UserAccountsDrawerHeader. In the future: FirebaseStore i do get an error: Undefined name 'FirebaseDatabase'. Try correcting the name to one that is defined, or defining the name. Maybe someone has any clue why FirebaseDatabase it comes out as a fault.

Thank you in advance!

My code snippet

UserAccountsDrawerHeader(
        accountEmail: FutureBuilder(
            future: FirebaseStore.instance
                .collection("Users")
                .doc(widget.uid)
                .once(),
            builder: (context, AsyncSnapshot<DataSnapshot> snapshot) {
              if (snapshot.hasData) {
                return Text(snapshot.data.value['email']);
              } else {
                return CircularProgressIndicator();
              }
            }),

Upvotes: 0

Views: 201

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80934

Firebase offers two kind of database services: Realtime database and Firestore, so if you are using Firestore then you have to do the following:

FirebaseFirestore.instance
                .collection("Users")
                .doc(widget.uid)
                .get(),

And if you are using realtime database then do:

FirebaseDatabase.instance
                .reference()
                .child(widget.uid),
                .once()

Upvotes: 1

Related Questions