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

前端 未结 2 1735
我寻月下人不归
我寻月下人不归 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: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

提交回复
热议问题