Skip to content

[local_auth_android 1.0.23] getAvailableBiometrics - Unhandled Exception: PlatformException #125236

@lukasgit

Description

@lukasgit

Is there an existing issue for this?

Possibly related to #125214

@stuartmorgan

Steps to reproduce

local_auth_android 1.0.23 - getAvailableBiometrics produces Unhandled Exception: PlatformException on some Android models.

local_auth_android 1.0.21 - Does not produce PlatformException error.

Expected results

_availableBiometrics = await _localAuth.getAvailableBiometrics(); should not return PlatformException error.

Actual results

PlatformException(channel-error, Unable to establish connection on channel., null, null)

Code sample
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';
import 'package:flutter/services.dart';
import 'dart:io' show Platform;


class BiometricsDataSource {
  final _localAuth = LocalAuthentication();
  List<BiometricType>? _availableBiometrics;

  bool isPlatformSupportedByLocalAuth =
      Platform.isAndroid || Platform.isIOS || Platform.isWindows;

  Future<bool> isAvailable() async {
    if (!isPlatformSupportedByLocalAuth) {
      return false;
    }

    late List<BiometricType> _availableBiometrics;
    try {
      _availableBiometrics = await _localAuth.getAvailableBiometrics();
    } on PlatformException catch (e) {
      debugPrint('[ERROR] local_auth getAvailableBiometrics: ${e}');
      return false;
    }

    if (await _localAuth.isDeviceSupported() &&
        await _localAuth.canCheckBiometrics &&
        _availableBiometrics.isNotEmpty
    ) {
      return true;
    } else {
      return false;
    }
  }
}
Logs
I/flutter (12402): [ERROR] local_auth getAvailableBiometrics: PlatformException(channel-error, Unable to establish connection on channel., null, null)
Doctor output
[✓] Flutter (Channel stable, 3.7.11, on [redacted])
    • Flutter version 3.7.11 on channel stable at [redacted]
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f72efea43c (9 days ago), 2023-04-11 11:57:21 -0700
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions