ensureSecurityKey static method
- BuildContext context,
- Widget child
Prompt user for security key if not available. Returns true if key is now available, false otherwise. Uses session caching to avoid repeated checks. Uses dialog mode instead of full-screen to avoid navigation issues on cancel.
Implementation
static Future<bool> ensureSecurityKey(
BuildContext context,
Widget child,
) async {
// Skip if already verified this session.
if (_securityKeyVerified) {
return true;
}
if (await isSecurityKeyAvailable()) {
_securityKeyVerified = true;
return true;
}
// Check if encryption has been set up.
if (!await hasEncryptionSetup()) {
if (!context.mounted) return false;
await showEncryptionNotSetupDialog(context);
return false;
}
// Prompt for security key using dialog mode (not full-screen)
// This avoids navigation issues when user cancels.
if (!context.mounted) return false;
final result = await showSecurityKeyDialog(context);
if (result) {
_securityKeyVerified = true;
_securityKeyAvailableCache = true; // Update cache
// Notify the status bar that security key is now available.
if (context.mounted) {
const SecurityKeyStatusChangedNotification(
isKeySaved: true,
).dispatch(context);
debugPrint('Security key status notification dispatched');
}
}
return result;
}