I\'m making a flutter app for my college project, where I\'m adding a login and signup page and authenticating it via Firebase, and when I click login the debug console says
I had same error and changed code to:
FirebaseUser user = (await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password)).user;
The app works as expected on a real device, without an error in the console, but Visual Studio Code shows red underline at the end below user and outputs an error:
The getter 'user' isn't defined for the class 'FirebaseUser'. Try importing the library that defines 'user', correcting the name to the name of an existing getter, or defining a getter or field named 'user'.
[Solution] Restart VS Code. VS Code uses the old library until restart.
It has been changed what you should do is
AuthResult result = await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
FirebaseUser user = result.user;
use User instead of FirebaseUser on firebase_auth 0.18.0+1
final User user = (await FirebaseAuth.instance.signInWithEmailAndPassword(
email: 'abc@gmail.com',
password: 'abc',
)).user;
signInWithEmailAndPassword returns AuthResult and AuthResult class contains instance variable user of type FirebaseUser. So You have to change your code as following way.
FirebaseUser userDetails = (await FirebaseAuth.instance
.signInWithEmailAndPassword(Credentialsxxx)).user;
print('sign in : ${userDetails.uid}');
I face the same issue. Just modify to be:
final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
See https://github.com/flutter/flutter/issues/38757#issuecomment-522307525
This is a breaking change in the plugin and its documented here https://pub.dev/packages/firebase_auth#0120
So you shouldn't do any type of casting you just have to refactor your code to adopt the new changes :
FirebaseUser user = (await FirebaseAuth.instance.
signInWithEmailAndPassword(email: email, password: password))
.user;