This Flutter plugin provides an feature for screen lock. Enter your passcode to unlock the screen. You can also use biometric authentication as an option.
- Any number of digits can be specified
- You can change
Cancel
andDelete
text - The UI expands and contracts according to the size of the device
- You can disable cancellation
- You can use biometrics
- Biometrics can be displayed on first launch
You can easily lock the screen with the following code.
To unlock, enter correctString.
import 'package:flutter_screen_lock/flutter_screen_lock.dart';
showLockScreen(
context: context,
correctString: '1234',
);
Default 4 digits can be changed. Change the correctString accordingly.
import 'package:flutter_screen_lock/flutter_screen_lock.dart';
showLockScreen(
context: context,
digits: 6,
correctString: '123456',
);
Specify canBiometric
and biometricFunction
.
biometricFunction
Add local_auth processing to biometricFunction
. See the following page for details.
https://pub.dev/packages/local_auth
import 'package:flutter_screen_lock/flutter_screen_lock.dart';
showLockScreen(
context: context,
correctString: '1234',
canBiometric: true,
biometricFunction: (context) async {
LocalAuthentication localAuth = LocalAuthentication();
bool didAuthenticate =
await localAuth.authenticateWithBiometrics(
localizedReason:
'Please authenticate to show account balance');
if (didAuthenticate) {
Navigator.of(context).maybePop();
}
},
);
add option showBiometricFirst.
showLockScreen(
context: context,
correctString: '1234',
canBiometric: true,
showBiometricFirst: true,
biometricFunction: (context) async {
LocalAuthentication localAuth = LocalAuthentication();
bool didAuthenticate =
await localAuth.authenticateWithBiometrics(
localizedReason:
'Please authenticate to show account balance');
if (didAuthenticate) {
Navigator.of(context).maybePop();
}
},
);
This is the case where you want to force authentication when the app is first launched.
showLockScreen(
context: context,
correctString: '1234',
canCancel: false,
);
You can change Cancel
and Delete
text.
We recommend no more than 6 characters at this time.
showLockScreen(
context: context,
correctString: '1234',
cancelText: 'Close',
deleteText: 'Remove',
);
use showConfirmPasscode
function.
showConfirmPasscode(
context: context,
confirmTitle: 'This is the second input.',
onCompleted: (context, verifyCode) {
// verifyCode is verified passcode
print(verifyCode);
// Please close yourself
Navigator.of(context).maybePop();
},
)