screenLock function

Future<void> screenLock({
  1. required BuildContext context,
  2. required String correctString,
  3. VoidCallback? onUnlocked,
  4. VoidCallback? onOpened,
  5. ValidationCallback? onValidate,
  6. VoidCallback? onCancelled,
  7. ValueChanged<int>? onError,
  8. ValueChanged<int>? onMaxRetries,
  9. int maxRetries = 0,
  10. Duration retryDelay = Duration.zero,
  11. Widget? title,
  12. ScreenLockConfig? screenLockConfig,
  13. SecretsConfig? secretsConfig,
  14. KeyPadConfig? keyPadConfig,
  15. DelayBuilderCallback? delayBuilder,
  16. Widget? customizedButtonChild,
  17. VoidCallback? customizedButtonTap,
  18. Widget? footer,
  19. Widget? cancelButton,
  20. Widget? deleteButton,
  21. InputController? inputController,
  22. SecretsBuilderCallback? secretsBuilder,
  23. bool useBlur = true,
  24. bool useLandscape = true,
  25. bool canCancel = true,
})

Animated ScreenLock

  • correctString: Input correct string (Required).
  • onUnlocked: Called if the value matches the correctString.
  • onOpened: For example, when you want to perform biometric authentication.
  • onValidate: Callback to validate input values filled in digits.
  • onCancelled: Called when the user cancels the screen.
  • onError: Called if the value does not match the correctString.
  • onMaxRetries: Events that have reached the maximum number of attempts.
  • maxRetries: 0 is unlimited. For example, if it is set to 1, didMaxRetries will be called on the first failure. Default 0.
  • retryDelay: Delay until we can retry. Duration.zero is no delay.
  • title: Change the title widget.
  • screenLockConfig: Configurations of ScreenLock.
  • secretsConfig: Configurations of Secrets.
  • keyPadConfig: Configuration of KeyPad.
  • delayBuilder: Specify the widget during input invalidation by retry delay.
  • customizedButtonChild: Child for bottom left side button.
  • customizedButtonTap: Tapped for left side lower button.
  • footer: Add a Widget to the footer.
  • cancelButton: Change the child widget for the delete button.
  • deleteButton: Change the child widget for the delete button.
  • inputController: Control inputs externally.
  • secretsBuilder: Custom secrets animation widget builder.
  • useBlur: Blur the background.
  • useLandscape: Use a landscape orientation. Default true.
  • canCancel: true is show cancel button.

Implementation

Future<void> screenLock({
  required BuildContext context,
  required String correctString,
  VoidCallback? onUnlocked,
  VoidCallback? onOpened,
  ValidationCallback? onValidate,
  VoidCallback? onCancelled,
  ValueChanged<int>? onError,
  ValueChanged<int>? onMaxRetries,
  int maxRetries = 0,
  Duration retryDelay = Duration.zero,
  Widget? title,
  ScreenLockConfig? screenLockConfig,
  SecretsConfig? secretsConfig,
  KeyPadConfig? keyPadConfig,
  DelayBuilderCallback? delayBuilder,
  Widget? customizedButtonChild,
  VoidCallback? customizedButtonTap,
  Widget? footer,
  Widget? cancelButton,
  Widget? deleteButton,
  InputController? inputController,
  SecretsBuilderCallback? secretsBuilder,
  bool useBlur = true,
  bool useLandscape = true,
  bool canCancel = true,
}) async {
  return Navigator.push<void>(
    context,
    PageRouteBuilder<void>(
      opaque: false,
      barrierColor: Colors.black.withOpacity(0.8),
      pageBuilder: (context, animation, secondaryAnimation) => WillPopScope(
        onWillPop: () async => canCancel && onCancelled == null,
        child: ScreenLock(
          correctString: correctString,
          onUnlocked: onUnlocked ?? Navigator.of(context).pop,
          onOpened: onOpened,
          onValidate: onValidate,
          onCancelled:
              canCancel ? onCancelled ?? Navigator.of(context).pop : null,
          onError: onError,
          onMaxRetries: onMaxRetries,
          maxRetries: maxRetries,
          retryDelay: retryDelay,
          title: title,
          screenLockConfig: screenLockConfig,
          secretsConfig: secretsConfig,
          keyPadConfig: keyPadConfig,
          delayBuilder: delayBuilder,
          customizedButtonChild: customizedButtonChild,
          customizedButtonTap: customizedButtonTap,
          footer: footer,
          cancelButton: cancelButton,
          deleteButton: deleteButton,
          inputController: inputController,
          secretsBuilder: secretsBuilder,
          useBlur: useBlur,
          useLandscape: useLandscape,
        ),
      ),
      transitionsBuilder: (context, animation, secondaryAnimation, child) =>
          SlideTransition(
        position: Tween<Offset>(
          begin: const Offset(0.0, 2.4),
          end: Offset.zero,
        ).animate(animation),
        child: SlideTransition(
          position: Tween<Offset>(
            begin: Offset.zero,
            end: const Offset(0.0, 2.4),
          ).animate(secondaryAnimation),
          child: child,
        ),
      ),
    ),
  );
}