unlockApp method

Future<bool> unlockApp()

Attempts to unlock the app using biometric authentication

This method will prompt the user for biometric authentication and unlock the app if successful.

Returns true if the app was successfully unlocked, false otherwise.

Example usage:

final unlocked = await context.unlockApp();
if (unlocked) {
  // App is now unlocked
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(content: Text('App unlocked successfully')),
  );
} else {
  // Failed to unlock
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(content: Text('Failed to unlock app')),
  );
}

Throws StateError if called outside of a Guardo widget context.

Implementation

Future<bool> unlockApp() async {
  final guardoState = _findGuardoStateNotifier();
  if (guardoState != null) {
    try {
      await guardoState.authenticate();
      return guardoState.isAuthenticated;
    } catch (e) {
      debugPrint('Failed to unlock app: $e');
      return false;
    }
  } else {
    throw StateError(
      'No GuardoStateNotifier found in widget tree. '
      'Make sure this context is within a Guardo widget.',
    );
  }
}