I have implemented the following login method and I am trying to use the isNewUser function to push a new screen:
Future<void> googleLogin() async {
try {
final googleUser = await GoogleSignIn().signIn();
if (googleUser == null) return;
final googleAuth = await googleUser.authentication;
final authCredential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
UserCredential userCredential =
await FirebaseAuth.instance.signInWithCredential(authCredential);
if (userCredential.additionalUserInfo!.isNewUser) {
return const SignUpNewUser();
}
} on FirebaseAuthException catch (e) {
AlertDialog(
title: const Text("Error"),
content: Text('Failed to sign in with Google: ${e.message}'),
);
}
}
I get the following error:
A value of type 'SignUpNewUser' can't be returned from the method 'googleLogin' because it has a return type of 'Future<void>'.
I'm pretty sure that I placed it in the correct spot to implement the function, but I have no idea how to do it in a Future.
CodePudding user response:
The problem is in the return type, you need change the type from void to dynamic.
Future<dynamic> googleLogin() async {...}
CodePudding user response:
you can return a widget directly but that doesn't makes sense so you need to use Navigator in order to push to a new screen.
Add
contextas parameter in the methodgoogleLogin()Use this
Navigator.push(context,MaterialPageRoute(builder: (context) =>your_new_screen()),);in the conditionuserCredential.additionalUserInfo!.isNewUserIn the above replace
your_new_screen()with the widget you have returned before ie.SignUpNewUser()
