简体   繁体   中英

flutter firebase googlesign in says - A value of type 'GoogleSignInAccount?' can't be assigned to a variable of type 'GoogleSignInAccount'

I know the same has been posted here, but doesn't seem to have an answer. I am having this red line underneath the GoogleSignIn, somewhere there has been a mention about downgrading the google_sign_in package version from 5.0.4 to 5.03, that hasn't helped me get rid of this error. here is my code so far -

[![enter image description here][1]][1]

GoogleSignIn().signIn() return GoogleSignInAccount? which means it might be null. On the other hand your googleUser variable is of type GoogleSignInAccount which means it can't be null. you should refactor your code to look like this:

Future<UserCredential?> signInWithGoogle() async {
  final GoogleSignInAccount? googleUser = GoogleSignIn().signIn();
  
  if (googleUser != null) {
     // Rest of the code
     ...
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM