Flutter Try-Catch block is not catching errors in local_auth plugin

126 Views Asked by At

I am calling LocalAuth.Authenticate() when a button is pressed. I tried to run the app with no Passcode/PIN set and therefore it should raise a "NotAvailable" error. But this error is not caught by the try-catch block and instead just outputs the error in debug console. Any help is appreciated!

Here's my home_page.dart code:

                     TextButton(
                        child: Text('YES'),
                        onPressed: () async {
                          try {
                            final authenticated = await LocalAuth.authenticate();
                            print(authenticated);
                            if (authenticated) {
                              DatabaseHelper.instance.deleteModel(id as int);
                              Navigator.pop(context);
                            }
                          } on PlatformException catch (e) {
                            print(e);
                          }
                        },
                      )

Debug Console output:

I/flutter (10972): error PlatformException(NotAvailable, Required security features not enabled, null, null)

0

There are 0 best solutions below