how to handle PlatformException while using firebase auth (flutter)

Viewed 56

This is my code below. I am using VS code. I am using flutter. Every time I enter the wrong OTP, I get an unhandled exception error. and no error is caught using the below code. I Need Help, please...

  try {
              auth.signInWithCredential(_credential).then(
                (value) {
                  Navigator.of(context).pushAndRemoveUntil(
                      MaterialPageRoute(
                        builder: (ctx) => const TabsScreen(),
                      ),
                      (Route route) => false);
                },
              );
            } on FirebaseAuthException catch (e) {
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(
                  content: Text('Enter Correct OTP'),
                ),
              );
            } on PlatformException catch (e) {
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(
                  content: Text('Enter Correct OTP'),
                ),
              );
            } catch (e) {
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(
                  content: Text('Enter Correct OTP'),
                ),
              );
            }

0 Answers
Related