jeudi 18 juin 2020

If statement not working and it says the return type should be void

User _returnUserFromFirebase(FirebaseUser user) {
    if(user==null) {
      return null;
    } else {
      return User(id:user.uid);
    }

}


Future<User> signInWithGoogle() async{
    GoogleSignIn _signIn = GoogleSignIn();
    GoogleSignInAccount _account= await _signIn.signIn();
    if(_account!=null){
      GoogleSignInAuthentication _authentication = await _account.authentication;
      if(_authentication.idToken!=null && _authentication.accessToken!=null){
        final AuthCredential _credential = GoogleAuthProvider.getCredential(idToken:
        _authentication.idToken, accessToken: _authentication.accessToken);
        final AuthResult _authResult = await _firebaseAuth.signInWithCredential(_credential);
        return _returnUserFromFirebase(_authResult.user);
      }
    }
  }

This function has a return type of 'Future', but doesn't end with a return statement. Try adding a return statement, or changing the return type to 'void'. What is the problem in this code? Is else necessary to add in this code after using two ifs? It is not even recognizing the return statement in the code.

Aucun commentaire:

Enregistrer un commentaire