isDeviceLockSet method
Checks whether the device has a screen lock (PIN, pattern, password, or passcode) configured.
This is a precondition for biometric enrollment on most platforms, but
the precise meaning of true varies per platform:
- Android: Authoritative. Uses
KeyguardManager.isDeviceSecure()and reports exactly whether a lock credential is enrolled. - iOS/macOS: Evaluates
LAPolicy.deviceOwnerAuthenticationand mapskLAErrorPasscodeNotSettofalse. Any other failure to evaluate the policy (e.g. on unusual or very old devices) is treated astrueto avoid false negatives. Thereforetruemeans "lock is set or indeterminate". If you need a stronger guarantee, rely on the reactive BiometricError.passcodeNotSet surfaced during the next operation. - Windows: Reports Windows Hello availability, not generic
screen-lock state. Uses
KeyCredentialManager.IsSupportedAsync(), which requires a Windows Hello PIN to be provisioned. Password-only local accounts will getfalsehere even though a screen lock is set. Treat the Windows return value as "can this device use Windows Hello for biometric operations?" rather than a direct equivalent of the Android check.
Returns true if the device has a screen lock configured (or the
platform-specific equivalent described above).
Implementation
Future<bool> isDeviceLockSet() async {
final pigeonVar_channelName =
'dev.flutter.pigeon.biometric_signature.BiometricSignatureApi.isDeviceLockSet$pigeonVar_messageChannelSuffix';
final pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else if (pigeonVar_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (pigeonVar_replyList[0] as bool?)!;
}
}