AppLockManager class

Locks the app when it has been in the background for longer than a grace period and unlocks it again with biometrics / device credentials.

final appLock = kit.createAppLockManager(
  gracePeriod: const Duration(seconds: 30),
)..start();
appLock.lockStateChanges.listen((locked) { /* show / hide lock screen */ });
// from the lock screen:
await appLock.unlock();
Mixed-in types

Constructors

AppLockManager({required BiometricRepository biometrics, Duration gracePeriod = Duration.zero, bool lockOnStart = false, String reason = 'Unlock to continue', bool allowDeviceCredential = true, DateTime now()?})
Throws ArgumentError when gracePeriod is negative or reason is blank.

Properties

allowDeviceCredential → bool
Whether PIN / pattern / passcode is accepted as a fallback.
final
gracePeriod → Duration
How long the app may stay in the background without locking.
final
hashCode → int
The hash code for this object.
no setterinherited
isLocked → bool
Whether the app is currently locked.
no setter
isUnlocking → bool
Whether an unlock prompt is currently showing.
no setter
lockStateChanges → Stream<bool>
Emits the new lock state whenever it changes.
no setter
reason → String
Default prompt text for unlock.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
inherited
didChangeAppLifecycleState(AppLifecycleState state) → void
Called when the system puts the app in the background or returns the app to the foreground.
override
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
inherited
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
inherited
didChangePlatformBrightness() → void
Called when the platform brightness changes.
inherited
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
inherited
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
inherited
didHaveMemoryPressure() → void
Called when the system is running low on memory.
inherited
didPopRoute() → Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
inherited
didPushRoute(String route) → Future<bool>
Called when the host tells the application to push a new route onto the navigator.
inherited
didPushRouteInformation(RouteInformation routeInformation) → Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
inherited
didRequestAppExit() → Future<AppExitResponse>
Called when a request is received from the system to exit the application.
inherited
dispose() → Future<void>
Stops observing and closes lockStateChanges.
forceUnlock() → void
Unlocks without a prompt, for apps that verified the user through their own fallback (e.g. an app PIN).
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
inherited
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
inherited
handleLifecycleChange(AppLifecycleState state) → void
Feeds a lifecycle change into the lock logic. Called automatically after start; public for apps that track the lifecycle themselves.
handleStartBackGesture(PredictiveBackEvent backEvent) → bool
Called at the start of a predictive back gesture.
inherited
handleStatusBarTap() → void
Called when the user taps the status bar on iOS, to scroll a scroll view to the top.
inherited
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
inherited
lock() → void
Locks immediately.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() → void
Starts observing the app lifecycle. Safe to call more than once.
toString() → String
A string representation of this object.
inherited
unlock({String? reason}) → Future<SecurityResult<bool>>
Shows the biometric prompt and unlocks on success.

Operators

operator ==(Object other) → bool
The equality operator.
inherited