local_auth iOS (Flutter)

420 Views Asked by At

Flutter local_auth didn't return platform exception when biometrics and passcode are disable for iOS.

I have a functionality where if biometrics and passcode are disable, I will use another function for authentication but it only works on Android and didn't work on iOS.

Future<bool> authentication() async {
    try {
      return await _localAuthentication.authenticate(
        localizedReason: Strings.localAuthReason,
        useErrorDialogs: true,
        stickyAuth: true,
      );
    } on PlatformException {
      return false;
    }
  }
1

There are 1 best solutions below

4
On

import this code below import 'package:local_auth/error_codes.dart' as local_auth_error;

and try this

 Future<bool> authentication() async {
try {
  return await _localAuthentication.authenticate(
    localizedReason: Strings.localAuthReason,
    useErrorDialogs: true,
    stickyAuth: true,
  );
} on PlatformException catch (exception) {
  if (exception.code == local_auth_error.notAvailable ||
      exception.code == local_auth_error.passcodeNotSet ||
      exception.code == local_auth_error.notEnrolled) {
    // Handle this exception here.
  }
}

}