Skip to content

[local_auth] authenticate() crashes the app on iOS when localizedReason is empty #77794

@enricobenedos

Description

@enricobenedos

Steps to Reproduce

  1. Run flutter create bug.
  2. Update the files as follows:
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: TextButton(
          child: Text('Start biometric auth'),
          onPressed: () async {
            final LocalAuthentication localAuth = LocalAuthentication();
            final bool canCheckBiometrics = await localAuth.canCheckBiometrics;

            if (canCheckBiometrics) {
              final List<BiometricType> availableBiometrics =
                  await localAuth.getAvailableBiometrics();
              if (availableBiometrics.length > 0) {
                print('Waiting for biometric authentication.');

                bool isAuthenticated;
                try {
                  isAuthenticated = await localAuth.authenticate(
                      localizedReason: ''
                      // localizedReason: I18n.of(context).login_biometricAuthMsg,
                      );
                } catch (e) {
                  print(e);
                  return;
                }
                if (isAuthenticated) {
                  print('Authenticated!!');
                } else {
                  print('Authentication failed!!');
                }
              }
            } else {
              print('Cannot check biometrics');
            }
          },
        ),
      ),
    );
  }
}
  1. Add local_auth: ^1.1.0 to pubspec.yaml
  2. Add the key to Info.plist file
<key>NSFaceIDUsageDescription</key>
<string>Why is my app authenticating using face id?</string>

Expected results:
I expect that the iOS simulator show me the FaceId/TouchId auth form, then I can emulate the face/finger recognition using the simulator tools.

Actual results:
When the app call authenticate() method completely crash with no info about the problem.

Logs

verbose_log.txt

Analyzing local_auth_bug...                                             
No issues found! (ran in 1.8s)
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.2 20D80 darwin-x64, locale en-GB)
    • Flutter version 2.0.1 at /Users/develop/SDKs/flutter
    • Framework revision c5a4b4029c (6 days ago), 2021-03-04 09:47:48 -0800
    • Engine revision 40441def69
    • Dart version 2.12.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/develop/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google
    Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.54.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.20.0

[✓] Connected device (1 available)
    • iPhone 12 Pro Max (mobile) • 3F2E6288-280C-45EF-BCA4-1236F663267E • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4
      (simulator)

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: qualityA truly polished experiencefound in release: 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: local_authPlugin for local authentificationpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions