1

I just updated Google Firebase Auth in Flutter app because I was getting some wried SDK errors but now I'm getting:

Error: 'currentUser' isn't a function or method and can't be invoked. User currentFirebaseUser = await FirebaseAuth.instance.currentUser();

I looked at the migration guide and understand that currentUser() is now synchronous via the currentUser getter. but I'm not sure how I should change my code now to fix this.

static void getCurrentUserInfo() async{

User currentFirebaseUser = await FirebaseAuth.instance.currentUser();
String userid = currentFirebaseUser.uid;

DatabaseReference userRef = FirebaseDatabase.instance.reference().child('users/$userid');
userRef.once().then((DataSnapshot snapshot){

  if(snapshot.value != null){

  }
});

}

maximus383
  • 584
  • 8
  • 25
  • If You want get user id actualy loget in try use some like this User currentFirebaseUser = await FirebaseAuth.instance.currentUser.then(op => { const lk = op.uid; }); –  Nov 11 '20 at 19:17

2 Answers2

8

you need to remove await and change currentUser() to currentUser.

So

User currentFirebaseUser = await FirebaseAuth.instance.currentUser();

Becomes

User currentFirebaseUser = FirebaseAuth.instance.currentUser;

Source: Verify email link and sign in
Let me know if this works ^_^

Abdullah Z Khan
  • 1,272
  • 1
  • 8
  • 18
0

Its done like this :

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userid = user.getUid();
Priyaank
  • 141
  • 6