Files
sure/mobile/lib/services/preferences_service.dart
Tristan Katana 9c199a6dcd feat(mobile): Add biometric lock for app resume (#1474)
* Feature: Biometric lock for app resume

User enables "Biometric Lock" in Settings → prompted to verify fingerprint/face first.
User backgrounds the app → _isLocked = true.
User returns → lock screen appears, auto-triggers biometric prompt.
Success → app unlocks, state preserved underneath.
Can retry or log out as fallback.
Add USE_BIOMETRIC permission to AndroidManifest.

* Fix: Remove duplicate local_auth entry in pubspec.lock and add NSFaceIDUsageDescription to iOS Info.plist

* fix(mobile) : Remove duplicate local auth files first

* fix(mobile): keep MainNavigationScreen in the Stack, let the lock screen float above, no unmounting

* Updtae: Swap out Flutter Activity for FlutterFragmentActivity that extends the lock scan feature

* fix(mobile): address biometric lock PR review feedback

* fix(mobile): only require biometric auth when enabling lock, not disabling

Prevents users from getting locked out if biometrics start failing —
they can now disable the lock without needing to pass biometric auth.

* fix(mobile): add missing closing brace in setBiometricEnabled

---------

Signed-off-by: Tristan Katana <50181095+felixmuinde@users.noreply.github.com>
2026-04-15 19:48:13 +02:00

65 lines
1.8 KiB
Dart

import 'package:shared_preferences/shared_preferences.dart';
class PreferencesService {
static const _groupByTypeKey = 'dashboard_group_by_type';
static const _biometricEnabledKey = 'biometric_enabled';
static const _showCategoryFilterKey = 'dashboard_show_category_filter';
static const _themeModeKey = 'theme_mode';
static PreferencesService? _instance;
SharedPreferences? _prefs;
PreferencesService._();
static PreferencesService get instance {
_instance ??= PreferencesService._();
return _instance!;
}
Future<SharedPreferences> get _preferences async {
_prefs ??= await SharedPreferences.getInstance();
return _prefs!;
}
Future<bool> getGroupByType() async {
final prefs = await _preferences;
return prefs.getBool(_groupByTypeKey) ?? false;
}
Future<void> setGroupByType(bool value) async {
final prefs = await _preferences;
await prefs.setBool(_groupByTypeKey, value);
}
Future<bool> getBiometricEnabled() async {
final prefs = await _preferences;
return prefs.getBool(_biometricEnabledKey) ?? false;
}
Future<void> setBiometricEnabled(bool value) async {
final prefs = await _preferences;
await prefs.setBool(_biometricEnabledKey, value);
}
Future<bool> getShowCategoryFilter() async {
final prefs = await _preferences;
return prefs.getBool(_showCategoryFilterKey) ?? false;
}
Future<void> setShowCategoryFilter(bool value) async {
final prefs = await _preferences;
await prefs.setBool(_showCategoryFilterKey, value);
}
/// Returns 'light', 'dark', or 'system' (default).
Future<String> getThemeMode() async {
final prefs = await _preferences;
return prefs.getString(_themeModeKey) ?? 'system';
}
Future<void> setThemeMode(String mode) async {
final prefs = await _preferences;
await prefs.setString(_themeModeKey, mode);
}
}