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

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[local_auth] support localizedFallbackTitle in IOSAuthMessages #5297

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.2

* Adds support `localizedFallbackTitle` in authenticateWithBiometrics on iOS.

## 1.0.1

* BREAKING CHANGE: Changes `stopAuthentication` to always return false instead of throwing an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ - (void)handleAuthReplyWithSuccess:(BOOL)success
case LAErrorTouchIDNotAvailable:
case LAErrorTouchIDNotEnrolled:
case LAErrorTouchIDLockout:
case LAErrorUserFallback:
[self handleErrors:error flutterArguments:arguments withFlutterResult:result];
return;
case LAErrorSystemCancel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class IOSAuthMessages extends AuthMessages {
this.goToSettingsButton,
this.goToSettingsDescription,
this.cancelButton,
this.localizedFallbackTitle,
});

/// Message advising the user to re-enable biometrics on their device.
Expand All @@ -35,6 +36,10 @@ class IOSAuthMessages extends AuthMessages {
/// Maximum 30 characters.
final String? cancelButton;

/// The localized title for the fallback button in the dialog presented to
/// the user during authentication.
final String? localizedFallbackTitle;

@override
Map<String, String> get args {
return <String, String>{
Expand All @@ -43,6 +48,8 @@ class IOSAuthMessages extends AuthMessages {
'goToSettingDescriptionIOS':
goToSettingsDescription ?? iOSGoToSettingsDescription,
'okButton': cancelButton ?? iOSOkButton,
if (localizedFallbackTitle != null)
'localizedFallbackTitle': localizedFallbackTitle!,
};
}

Expand All @@ -54,14 +61,16 @@ class IOSAuthMessages extends AuthMessages {
lockOut == other.lockOut &&
goToSettingsButton == other.goToSettingsButton &&
goToSettingsDescription == other.goToSettingsDescription &&
cancelButton == other.cancelButton;
cancelButton == other.cancelButton &&
localizedFallbackTitle == other.localizedFallbackTitle;

@override
int get hashCode =>
lockOut.hashCode ^
goToSettingsButton.hashCode ^
goToSettingsDescription.hashCode ^
cancelButton.hashCode;
cancelButton.hashCode ^
localizedFallbackTitle.hashCode;
Copy link
Contributor

@hellohuanlin hellohuanlin Apr 20, 2022

Choose a reason for hiding this comment

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

just curious: i'm wondering does dart auto synthesize the hash function (like in swift)? manually implement this can be error prone (e.g. forgetting to include an attribute).

Also interesting choice using xor to combine hashes, because normally we use aBigPrimeNumber * A + B. Using xor comes with a few drawbacks like missing order information, common collision with +x, -x pairs, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

for example, in java's Arrays we use

  result = 31 * result + element;

Copy link
Contributor

Choose a reason for hiding this comment

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

Also interesting choice using xor to combine hashes

We should update this to the new Object.hash; that's out of scope for this PR though. I'll do a sweep for old manual hash implementations and send you a PR.

}

// Default Strings for IOSAuthMessages plugin. Currently supports English.
Expand Down
2 changes: 1 addition & 1 deletion packages/local_auth/local_auth_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: local_auth_ios
description: iOS implementation of the local_auth plugin.
repository: https://github.com/flutter/plugins/tree/master/packages/local_auth/local_auth_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
version: 1.0.1
version: 1.0.2

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
23 changes: 23 additions & 0 deletions packages/local_auth/local_auth_ios/test/local_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ void main() {
);
});

test('authenticate with `localizedFallbackTitle`', () async {
await localAuthentication.authenticate(
authMessages: <AuthMessages>[
const IOSAuthMessages(localizedFallbackTitle: 'Enter PIN'),
],
localizedReason: 'Needs secure',
);
expect(
log,
<Matcher>[
isMethodCall('authenticate',
arguments: <String, dynamic>{
'localizedReason': 'Needs secure',
'useErrorDialogs': true,
'stickyAuth': false,
'sensitiveTransaction': true,
'biometricOnly': false,
'localizedFallbackTitle': 'Enter PIN',
}..addAll(const IOSAuthMessages().args)),
],
);
});

test('authenticate with no sensitive transaction.', () async {
await localAuthentication.authenticate(
authMessages: <AuthMessages>[const IOSAuthMessages()],
Expand Down