feat: Add theme customization options in settings screen and update app theme logic
This commit is contained in:
+36
-3
@@ -19,6 +19,7 @@ import 'package:notas/widgets/app_title_bar.dart';
|
||||
import 'package:notas/widgets/sync_status_indicator.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
enum _AppSection {
|
||||
@@ -50,6 +51,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
static const Duration _screenTransitionDuration = Duration(milliseconds: 280);
|
||||
static const Duration _biometricInactivityTimeout = Duration(minutes: 5);
|
||||
static const Duration _syncInterval = Duration(minutes: 5);
|
||||
static const String _themeSeedColorKey = 'theme_seed_color_v1';
|
||||
|
||||
final LocalVaultService _vaultService = LocalVaultService.instance;
|
||||
final GlobalKey<ScaffoldMessengerState> _scaffoldMessengerKey =
|
||||
@@ -71,6 +73,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
SyncStatus _syncStatus = SyncStatus.idle;
|
||||
String? _syncErrorMessage;
|
||||
int _homeRefreshToken = 0;
|
||||
Color _themeSeedColor = Colors.amber;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -80,6 +83,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
windowManager.addListener(this);
|
||||
windowManager.setPreventClose(true);
|
||||
}
|
||||
_loadThemeSeedColor();
|
||||
_bootstrapVault();
|
||||
}
|
||||
|
||||
@@ -96,6 +100,33 @@ class _NotesAppState extends State<NotesApp>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadThemeSeedColor() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final int? storedColorValue = prefs.getInt(_themeSeedColorKey);
|
||||
if (storedColorValue == null || !mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_themeSeedColor = Color(storedColorValue);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setThemeSeedColor(Color color) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(_themeSeedColorKey, color.value);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_themeSeedColor = color;
|
||||
});
|
||||
}
|
||||
|
||||
ThemeData get _theme => AppTheme.theme(seedColor: _themeSeedColor);
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (_isUnlocking) {
|
||||
@@ -669,7 +700,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
navigatorKey: _navigatorKey,
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.theme,
|
||||
theme: _theme,
|
||||
home: const Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
@@ -700,7 +731,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: _scaffoldMessengerKey,
|
||||
theme: AppTheme.theme,
|
||||
theme: _theme,
|
||||
home: home,
|
||||
);
|
||||
}
|
||||
@@ -722,6 +753,8 @@ class _NotesAppState extends State<NotesApp>
|
||||
onDeleteAllData: _resetLocalVaultData,
|
||||
onBackToHome: _openHome,
|
||||
onForceSync: () => _performSync(forceFull: true),
|
||||
currentSeedColor: _themeSeedColor,
|
||||
onThemeColorSelected: _setThemeSeedColor,
|
||||
);
|
||||
|
||||
return MaterialApp(
|
||||
@@ -729,7 +762,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: _scaffoldMessengerKey,
|
||||
theme: AppTheme.theme,
|
||||
theme: _theme,
|
||||
home: Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.f5): const PerformSyncIntent(),
|
||||
|
||||
Reference in New Issue
Block a user