Flutter : Google Login pop up wont appear to select an account

Viewed 753

I've created a login screen where when user press on the login button it calls out an event LoginButtonOnPressedEvent. Below is my onLoginButtonOnPressedEvent function in my LoginBloc class.

 Future<void> _onLoginButtonPressedEvent(
  LoginButtonPressedEvent event, Emitter<LoginScreenState> emit) async {
  GoogleSignIn _googleSignIn = GoogleSignIn(scopes: ['email']);
  GoogleSignInAccount? user = _googleSignIn.currentUser;
  await _googleSignIn.signIn();
  emit(LoginScreenState(user: user));
  print("USER DETAILS  : ${user}");
}

and I'm triggering this event in my LoginScreen as below where RippleButton is a custom button I made.

RippleButton(
          onTap: () {
            context.read<LoginScreenBloc>().add(LoginButtonPressedEvent());
          },
        ),

when I tap on the button,the popup to select an account wont show,instead the screen becomes a bit dark and then go back to normal.

Below is the log related to calling the event

I/ContentCaptureHelper(30073): Setting logging level to OFF
I/flutter (30073): USER DETAILS  : null
I/et_schedule_ap(30073): Background concurrent copying GC freed 2871953(94MB) AllocSpace 
objects, 9(308KB) LOS objects, 87% free, 3450KB/27MB, paused 142us,42us total 104.801ms
W/et_schedule_ap(30073): Reducing the number of considered missed Gc histogram windows 
from 171 to 100

Please help!!!

1 Answers

Simply use this:-

Future<void> _onLoginButtonPressedEvent() async {
  GoogleSignIn _googleSignIn = GoogleSignIn();
  try {
    GoogleSignInAccount? result = await _googleSignIn.signIn();

    name = result!.displayName;
    email = result.email;
    password = result.id;
     
    print(result);
  } catch (error) {
    print(error);
  }
}
Related