'Opening new page when it is the first time to login in only ? Flutter firebase

I am creating an app and I wanna use to give me some information if it's his first login

EDIT

My code works fine when I tell him to print whether it's a first user or not but when I made him return routes it doesn't work.

Future<void> signInWithGoogle() async {
try {
  GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
  GoogleSignInAuthentication googleSignInAuthentication =
      await googleSignInAccount.authentication;
  AuthCredential authCredential = GoogleAuthProvider.credential(
      idToken: googleSignInAuthentication.idToken,
      accessToken: googleSignInAuthentication.accessToken);
  UserCredential authResult =
      await _auth.signInWithCredential(authCredential);

  if (authResult.additionalUserInfo.isNewUser) {
    return ContactPage();
  } else {
    return HomePage();
  }
} catch (e) {
  print(e.toString());
}

}

My Debug Console

D/EGL_emulation(17377): eglMakeCurrent: 0xf1162c20: ver 2 0 (tinfo 0xf11fd950) W/ple.calling_ap(17377): Accessing hidden method Lsun/misc/Unsafe;->getUnsafe()Lsun/misc/Unsafe; (greylist,core-platform-api, linking, allowed) W/ple.calling_ap(17377): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed) W/ple.calling_ap(17377): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed) W/ple.calling_ap(17377): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed) W/ple.calling_ap(17377): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed) I/FirebaseAuth(17377): [FirebaseAuth:] Preparing to create service connection to fallback implementation 2 W/System (17377): Ignoring header X-Firebase-Locale because its value was null. D/FirebaseAuth(17377): Notifying id token listeners about user ( YJNbeDYPgFSVz5e3xKun6nJe8643 ).



Solution 1:[1]

From your question, I got that you want to see if the user is new to your application mean when user first time logins to your app, you want to show some additional information to. When you call googlelogin() method it return UserCrendtials user and a you can check by user.additionalUserInfo.isNewUser. It returns true if user is new and false if your users is not new to your app. Hopefully Your code will look like this:

var user = googlelogin();
if(user.additionalUserInfo.isNewUser){
  //DO whatever you want to do, 
}else{
  //Continue with app flow
}

hope it will solve your problem. However I didn't get what you are trying to do in your streambuilder and how can you improve this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 K_Chandio