A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'

前端 未结 2 1731
我寻月下人不归
我寻月下人不归 2021-01-23 22:57

I\'m implementing the google sign in method in my project using Firebase Google sign in option, when the add the below line in my code its throwing me the error like:

         


        
相关标签:
2条回答
  • 2021-01-23 23:26

    Simple solution (caused by a type change):

    Firebase has recently changed its type 'FirebaseUser' (which is depreciated now) type to 'User'. Try renaming the same in your code and that should be the solution. In my case it worked for most of the same errors.

    Best

    0 讨论(0)
  • 2021-01-23 23:38

    The method firebaseAuth.signInWithCredential(credential) returns a value of type AuthResult, therefore you need to do the following :

    AuthResult userDetails = await _firebaseAuth.signInWithCredential(credential);
    

    The other alternative and the better one for your code, is since signInWithCredential returns AuthResult and since class AuthResult contains instance variable user of type FirebaseUser, then you can do the following:

    FirebaseUser userDetails = (await _firebaseAuth.signInWithCredential(credential)).user;
    

    https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_auth/firebase_auth/lib/src/auth_result.dart#L18

    0 讨论(0)
提交回复
热议问题