[local_auth] Fix iOS crash when no localizedReason (#3780)
diff --git a/packages/local_auth/CHANGELOG.md b/packages/local_auth/CHANGELOG.md
index 429e217..f6c3848 100644
--- a/packages/local_auth/CHANGELOG.md
+++ b/packages/local_auth/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.1.4
+
+* Add debug assertion that `localizedReason` in `LocalAuthentication.authenticateWithBiometrics` must not be empty.
+
## 1.1.3
* Fix crashes due to threading issues in iOS implementation.
diff --git a/packages/local_auth/lib/local_auth.dart b/packages/local_auth/lib/local_auth.dart
index 3f33259..0b75a83 100644
--- a/packages/local_auth/lib/local_auth.dart
+++ b/packages/local_auth/lib/local_auth.dart
@@ -59,7 +59,7 @@
///
/// [localizedReason] is the message to show to user while prompting them
/// for authentication. This is typically along the lines of: 'Please scan
- /// your finger to access MyApp.'
+ /// your finger to access MyApp.'. This must not be empty.
///
/// [useErrorDialogs] = true means the system will attempt to handle user
/// fixable issues encountered while authenticating. For instance, if
@@ -100,7 +100,8 @@
bool sensitiveTransaction = true,
bool biometricOnly = false,
}) async {
- assert(localizedReason != null);
+ assert(localizedReason.isNotEmpty);
+
final Map<String, Object> args = <String, Object>{
'localizedReason': localizedReason,
'useErrorDialogs': useErrorDialogs,
diff --git a/packages/local_auth/pubspec.yaml b/packages/local_auth/pubspec.yaml
index 5e2dbb4..eccc2f8 100644
--- a/packages/local_auth/pubspec.yaml
+++ b/packages/local_auth/pubspec.yaml
@@ -2,7 +2,7 @@
description: Flutter plugin for Android and iOS devices to allow local
authentication via fingerprint, touch ID, face ID, passcode, pin, or pattern.
homepage: https://github.com/flutter/plugins/tree/master/packages/local_auth
-version: 1.1.3
+version: 1.1.4
flutter:
plugin:
diff --git a/packages/local_auth/test/local_auth_test.dart b/packages/local_auth/test/local_auth_test.dart
index d0a4dc8..b24de8b 100644
--- a/packages/local_auth/test/local_auth_test.dart
+++ b/packages/local_auth/test/local_auth_test.dart
@@ -73,6 +73,17 @@
);
});
+ test('authenticate with no localizedReason on iOS.', () async {
+ setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));
+ await expectLater(
+ localAuthentication.authenticate(
+ localizedReason: '',
+ biometricOnly: true,
+ ),
+ throwsAssertionError,
+ );
+ });
+
test('authenticate with no sensitive transaction.', () async {
setMockPathProviderPlatform(FakePlatform(operatingSystem: 'android'));
await localAuthentication.authenticate(