Home > Back-end >  how to get the current users uid from firebase in flutter? [duplicate]
how to get the current users uid from firebase in flutter? [duplicate]

Time:10-02

I need to retrieve the 'uid' of the current user in my flutter app and use it as a global variable. throughout the page

CodePudding user response:

Update (2020.09.09) After firebase_auth version 0.18.0

Few breaking updates were made in firebase_auth 0.18.0. FirebaseUser is now called User, currentUser is a getter, and currentUser is synchronous.

This makes the code for getting uid like this:

final FirebaseAuth auth = FirebaseAuth.instance;
 void inputData() {
    final User user = auth.currentUser;
    final uid = user.uid;
    // here you write the codes to input the data into firestore
}

Then you can create a Global class FirebaseCalls call put all the functions needed there and call it in any class you want .

CodePudding user response:

final FirebaseAuth auth = FirebaseAuth.instance;
    
final User user = auth.currentUser;
final uid = user.uid;
  • Related