Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

stuartmorgan-g
Copy link
Collaborator

Switches from PlatformExceptions to new LocalAuthExceptions, which contain structured error information (specifically, a code that is a documented enum, rather than a list of magic strings that are used inconsistently and not all documented), bringing the plugin into alignment with [our current best practices](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#platform-exception-handling. In addition to being clearer and easier to use for clients, this adds significantly more granular error codes than we currently have, which allows clients to better handle specific cases.

Since this must be done as a breaking change (since the current PlatformExceptions are a combination of documented and de-facto API), this batches another breaking change, which is removing the error dialogs from the plugin, for the reasons described in flutter/flutter#175125.

Since this is adding far more specific error codes, the PR also makes the internal change of passing essentially all native failure cases across the language boundary and then doing mapping to the cross-platform codes in Dart code, in keeping with our general recent practice of moving logic to the Dart side when there's no need for it to be native.

Fixes flutter/flutter#113687
Fixes flutter/flutter#175125
Fixes flutter/flutter#151513
Fixes flutter/flutter#132757
Fixes flutter/flutter#148947
Fixes flutter/flutter#173506
Fixes flutter/flutter#174191
Closes flutter/flutter#96646
Fixes flutter/flutter#117810
Closes flutter/flutter#141283
Closes flutter/flutter#173142

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@stuartmorgan-g
Copy link
Collaborator Author

@tarrinneal Please review everything other than the Android and iOS changes.

@stuartmorgan-g stuartmorgan-g added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage labels Sep 9, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring of the local_auth plugin. It successfully replaces PlatformException with a more robust, structured LocalAuthException, and removes the useErrorDialogs option, giving developers more control over the user experience. The changes are consistently applied across all supported platforms, and the public API of the local_auth package is cleaner as a result. My review includes a few minor suggestions to improve the example applications to better demonstrate handling of the new exception type.

stuartmorgan-g and others added 3 commits September 11, 2025 10:53
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagged a few typos, but the (non-ios, non-android) code all looks solid to me.

Comment on lines +95 to 106
print(e);
setState(() {
_isAuthenticating = false;
if (e.code != LocalAuthExceptionCode.userCanceled &&
e.code != LocalAuthExceptionCode.systemCanceled) {
_authorized =
'Error - ${e.code.name}${e.description != null ? ': ${e.description}' : ''}';
}
});
return;
} on PlatformException catch (e) {
print(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is having print statements in catch blocks normal for our examples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not uncommon; our examples have historically been pretty bare-bones, and tend to skew more toward enabling manual testing than showing best practices. Some stick the errors into some in-app UI, which is an improvement, but also more code in the example.

It's something that ideally we should address, but polishing example apps that most clients will probably never actually run is also pretty low priority, so I've never followed up on it.

Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS side LGTM

Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that Gemini didn't catch those typos, it's caught similar mistakes in other PRs.

Copy link
Contributor

@mboetger mboetger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the Android side.

Aside, my brain does not like 'canceled' with one 'l' no matter how many times Google tells me that's how we do it here in America.

@stuartmorgan-g
Copy link
Collaborator Author

Aside, my brain does not like 'canceled' with one 'l' no matter how many times Google tells me that's how we do it here in America.

If I hadn't been interacting with the Android error codes there's no way I would have actually remembered to do it that way (per Flutter style).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants