Search code examples
androidflutterflutter-dependenciesgoogle-signin

Flutter Sign In Screen, Sign in with Google shows "An unknown error occurred"


After upgrading to Flutter 3.10, I built my android app using Flutter Sign In Screen. When I click the "Sign in with Google" button, a dialog is displayed for me to select my Google account. After selection, The sign in screen shows that an unknown error occurred. I have even upgraded the packages, but no change.enter image description here

Here is a section of main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  /// The app uses Email and GoogleProvider to sign in.
  FirebaseUIAuth.configureProviders([
    EmailAuthProvider(),
    GoogleProvider(
        clientId:
            'CLIENT ID IS HERE'),
    // ... other providers can be added here if necessary
  ]);

  /// This prevents the app from rotating to landscape mode.
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((_) {
    runApp(EasyDynamicThemeWidget(child: const MyApp()));
  });
}

This is a section of my auth_gate.dart:

class _AuthGateState extends State<AuthGate> {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return SignInScreen(
            headerBuilder: (context, constraints, _) {
              return Image.asset("assets/qaizenlogo.png");
            },
            footerBuilder: (context, action) {
              return Padding(
                  padding: const EdgeInsets.only(top: 40.0),
                  child: Text.rich(TextSpan(text: 'Need help? ', children: [
                    TextSpan(
                        text: 'Call Us',
                        style: const TextStyle(
                          //color: Theme.of(context).primaryColor,
                          color: Colors.deepPurple,
                          fontSize: 16,
                          decoration: TextDecoration.underline,
                          fontStyle: FontStyle.italic,
                          fontWeight: FontWeight.bold,
                        ),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            showDialog(
                                context: context,
                                builder: (ctx) => AlertDialog(
                                      icon: const Icon(
                                        Icons.phone_outlined,
                                        color: Colors.blue,
                                      ),
                                      title: const Text("Call Us"),
                                      content: const Text(
                                        "We're here to help with any questions or concerns you may have. Do you want to proceed with the call?",
                                        style: TextStyle(fontSize: 18),
                                      ),
                                      actions: <Widget>[
                                        TextButton(
                                          onPressed: () async {
                                            Navigator.of(ctx).pop();
                                            //call
                                            //when call permission is granted:
                                            await FlutterPhoneDirectCaller
                                                .callNumber('PHONE NUMBER GOES HERE');
                                            //else not granted, just show phone number
                                            if (await Permission
                                                .phone.isDenied) {
                                              makePhoneCall();
                                            }
                                          },
                                          child: Text(
                                            "Yes",
                                            style: TextStyle(
                                                fontSize: 16,
                                                color: Theme.of(context)
                                                    .primaryColor),
                                          ),
                                        ),
                                        TextButton(
                                          onPressed: () =>
                                              Navigator.of(ctx).pop(),
                                          child: Text(
                                            "No",
                                            style: TextStyle(
                                                fontSize: 17,
                                                color: Theme.of(context)
                                                    .primaryColor),
                                          ),
                                        ),
                                      ],
                                    ));
                          })
                  ])));
            },
          );
        }
        return const HomeScreen();
      },
    );
  }
}

enter image description here


Solution

  • I found what was the cause of my app not signing in with Google. I did not add Google Play's App signing key certificate to Firebase.

    Google Play Console > [MyApp] > Setup > App integrity > App signing