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 #5296

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions packages/local_auth/local_auth_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 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 @@ -180,6 +180,7 @@ - (void)handleAuthReplyWithSuccess:(BOOL)success
case LAErrorPasscodeNotSet:
case LAErrorTouchIDNotAvailable:
case LAErrorTouchIDNotEnrolled:
case LAErrorUserFallback:
case LAErrorTouchIDLockout:
[self handleErrors:error flutterArguments:arguments withFlutterResult:result];
return;
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