1

I have created login application, using flutter and firebase. i am doing google login. I have 2 pages login.dart and homepage.dart where everything happens. When i click on login button it asks for choose an account and take me to homepage, but when i logout, and again try to login it takes me automatically to homepage, but i want it to ask again for choosing an account.

I have created signout() function in loginpage itself, where I have written the code for the rest of the authentication, but when I call this function in homepage.dart in logout button, it wont come.

Code for Login Authentication in loginpage.dart

class _LoginPageState extends State<LoginPage> {
  String _email;
  String _password;

  //google sign in
  final GoogleSignIn googleSignIn=  GoogleSignIn();
  final FirebaseAuth _auth = FirebaseAuth.instance;
  Future<FirebaseUser> _signIn() async{
    //GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
    GoogleSignInAccount googleUser = await googleSignIn.signIn();
    GoogleSignInAuthentication googleAuth = await googleUser.authentication;
    final AuthCredential credential = GoogleAuthProvider.getCredential(
      idToken: googleAuth.idToken,
      accessToken: googleAuth.accessToken,
    );
    final FirebaseUser user = await _auth.signInWithCredential(credential);
    print("User Name: ${user.displayName}");
    assert(await user.getIdToken() != null);
    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);
    Navigator.of(context).pushReplacementNamed('/homepage');
  }

  Future<void> signOut() async {
  return googleSignIn.signOut();
  }

code for log out button in homepage.dart

 MaterialButton(
                  onPressed: () {
                    signOut
                    FirebaseAuth.instance.signOut().then((value) {
                      Navigator.of(context).pushReplacementNamed('/landingpage');
                    })
                        .catchError((e){
                      print(e);
                    });
                  },
                child: Text('Log Out'),
              )

Please Help me out

kay
  • 13
  • 3
  • signOut() is used in LogOut Button i missed () while posting this – kay May 16 '19 at 13:16
  • You should be able to force the account chooser as shown here: https://stackoverflow.com/questions/33782838/change-user-with-firebase-google-user-authentication. I'm not sure if that's available in Flutter though. – Frank van Puffelen May 16 '19 at 13:17

0 Answers0