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

Commit

Permalink
[local_auth] support localizedFallbackTitle in IOSAuthMessages (#5297)
Browse files Browse the repository at this point in the history
  • Loading branch information
furaiev authored Apr 20, 2022
1 parent 102cf1b commit f29c36c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
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;
}

// 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

0 comments on commit f29c36c

Please sign in to comment.