Repository navigation
[local_auth] Suggestion for changes in error handling for LocalAuthentication().authenticate() #151513
Description
Use case
I'd like to suggest some changes to the error handling for the biometric authentication features provided by the local_auth library.
Currently, there are some differences in how errors are handled on iOS and Android.
I'm particularly focused on one specific situation on iOS: when iOS biometric authentication is voluntarily cancelled by the user.
Proposal
- For cases when iOS biometric authentication is voluntarily cancelled by the user:
Currently, when a user voluntarily cancels the iOS biometric authentication, a PlatformException with error PlatformException(NotAvailable, Authentication canceled., com.apple.LocalAuthentication, null) is returned on Flutter's end.
This PlatformException is indistinguishable from the PlatformException(NotAvailable, Authentication failure., com.apple.LocalAuthentication, null) returned when biometric authentication fails consecutively.
This makes it difficult to properly handle each exception.
However, on Android, when a user voluntarily cancels the authentication, the return value of LocalAuthentication().authenticate() is false.
Therefore, to make it easier to differentiate between the two exceptions, I propose that for voluntarily cancelled iOS biometric authentication, like Android, the return value of LocalAuthentication().authenticate() should be false.
I believe that this can be achieved by adding kLAErrorUserCancel to the iOS source code.
I believe that the issue could be resolved by writing a code as follows.


Activity
[-]local_auth: Suggestion for changes in error handling for LocalAuthentication().authenticate()[/-][+][local_auth] Suggestion for changes in error handling for LocalAuthentication().authenticate()[/+]stuartmorgan-g commentedon Jul 16, 2024
In general we want to unify error handling across all platforms in our plugins (tracking issue for local_auth), which is a large project, but this looks like a case where we could incrementally make this specific change without a breaking change, so would be good to do in the short term.
[local_auth] Adopt structured errors, and remove `useErrorDialogs` (f…
github-actions commentedon Oct 31, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[local_auth] Adopt structured errors, and remove `useErrorDialogs` (f…