blob: b3b0a653b514f544b05f69c502a599c2ebae9774 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/services.dart';
import 'local_auth_platform_interface.dart';
const MethodChannel _channel = MethodChannel('');
/// The default interface implementation acting as a placeholder for
/// the native implementation to be set.
/// This implementation is not used by any of the implementations in this
/// repository, and exists only for backward compatibility with any
/// clients that were relying on internal details of the method channel
/// in the pre-federated plugin.
class DefaultLocalAuthPlatform extends LocalAuthPlatform {
Future<bool> authenticate({
required String localizedReason,
required Iterable<AuthMessages> authMessages,
AuthenticationOptions options = const AuthenticationOptions(),
}) async {
final Map<String, Object> args = <String, Object>{
'localizedReason': localizedReason,
'useErrorDialogs': options.useErrorDialogs,
'stickyAuth': options.stickyAuth,
'sensitiveTransaction': options.sensitiveTransaction,
'biometricOnly': options.biometricOnly,
for (final AuthMessages messages in authMessages) {
return (await _channel.invokeMethod<bool>('authenticate', args)) ?? false;
Future<List<BiometricType>> getEnrolledBiometrics() async {
final List<String> result = (await _channel.invokeListMethod<String>(
)) ??
final List<BiometricType> biometrics = <BiometricType>[];
for (final String value in result) {
switch (value) {
case 'face':
case 'fingerprint':
case 'iris':
case 'undefined':
// Sentinel value for the case when nothing is enrolled, but hardware
// support for biometrics is available.
return biometrics;
Future<bool> deviceSupportsBiometrics() async {
final List<String> availableBiometrics =
(await _channel.invokeListMethod<String>(
)) ??
// If anything, including the 'undefined' sentinel, is returned, then there
// is device support for biometrics.
return availableBiometrics.isNotEmpty;
Future<bool> isDeviceSupported() async =>
(await _channel.invokeMethod<bool>('isDeviceSupported')) ?? false;
Future<bool> stopAuthentication() async =>
await _channel.invokeMethod<bool>('stopAuthentication') ?? false;