feat: Optimize theme data handling and simplify widget structure in NotesApp

This commit is contained in:
2026-05-21 17:02:05 +02:00
parent 063b300428
commit 62d47904d9
+35 -38
View File
@@ -102,6 +102,7 @@ class _NotesAppState extends State<NotesApp>
setState(() { setState(() {
_themeSeedColor = Color(storedColorValue); _themeSeedColor = Color(storedColorValue);
_themeData = AppTheme.theme(seedColor: _themeSeedColor);
}); });
} }
@@ -115,10 +116,14 @@ class _NotesAppState extends State<NotesApp>
setState(() { setState(() {
_themeSeedColor = color; _themeSeedColor = color;
_themeData = AppTheme.theme(seedColor: _themeSeedColor);
}); });
} }
ThemeData get _theme => AppTheme.theme(seedColor: _themeSeedColor); // Cached ThemeData to avoid recomputing on every build.
ThemeData? _themeData;
ThemeData get _theme => _themeData ??= AppTheme.theme(seedColor: _themeSeedColor);
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
@@ -767,12 +772,7 @@ class _NotesAppState extends State<NotesApp>
} }
Widget _buildLoadingScreen() { Widget _buildLoadingScreen() {
return MaterialApp( return const Scaffold(
navigatorKey: _navigatorKey,
title: 'Mis Notas',
debugShowCheckedModeBanner: false,
theme: _theme,
home: const Scaffold(
body: SafeArea( body: SafeArea(
child: Column( child: Column(
children: [ children: [
@@ -791,19 +791,11 @@ class _NotesAppState extends State<NotesApp>
], ],
), ),
), ),
),
); );
} }
Widget _buildAppShell({required Widget home}) { Widget _buildAppShell({required Widget home}) {
return MaterialApp( return home;
navigatorKey: _navigatorKey,
title: 'Mis Notas',
debugShowCheckedModeBanner: false,
scaffoldMessengerKey: _scaffoldMessengerKey,
theme: _theme,
home: home,
);
} }
Widget _buildMainShell(NoteRepository repository) { Widget _buildMainShell(NoteRepository repository) {
@@ -829,13 +821,7 @@ class _NotesAppState extends State<NotesApp>
onThemeColorSelected: _setThemeSeedColor, onThemeColorSelected: _setThemeSeedColor,
); );
return MaterialApp( return Shortcuts(
navigatorKey: _navigatorKey,
title: 'Mis Notas',
debugShowCheckedModeBanner: false,
scaffoldMessengerKey: _scaffoldMessengerKey,
theme: _theme,
home: Shortcuts(
shortcuts: <LogicalKeySet, Intent>{ shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.f5): const PerformSyncIntent(), LogicalKeySet(LogicalKeyboardKey.f5): const PerformSyncIntent(),
}, },
@@ -897,7 +883,6 @@ class _NotesAppState extends State<NotesApp>
), ),
), ),
), ),
),
); );
} }
@@ -951,21 +936,22 @@ class _NotesAppState extends State<NotesApp>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_isBootstrapping) { Widget homeWidget;
return _buildLoadingScreen();
}
if (_isBootstrapping) {
homeWidget = _buildLoadingScreen();
} else {
final NoteRepository? repository = _repository; final NoteRepository? repository = _repository;
if (repository != null) { if (repository != null) {
return _buildMainShell(repository); homeWidget = _buildMainShell(repository);
} } else {
switch (_phase) { switch (_phase) {
case _AppPhase.loading: case _AppPhase.loading:
return _buildLoadingScreen(); homeWidget = _buildLoadingScreen();
break;
case _AppPhase.access: case _AppPhase.access:
return _buildAppShell( homeWidget = _buildAppShell(
home: VaultAccessScreen( home: VaultAccessScreen(
isBusy: _isUnlocking, isBusy: _isUnlocking,
onCreateAccountPressed: (String email, String password) async { onCreateAccountPressed: (String email, String password) async {
@@ -985,8 +971,9 @@ class _NotesAppState extends State<NotesApp>
onContinueWithoutAccount: _enterWithoutAccount, onContinueWithoutAccount: _enterWithoutAccount,
), ),
); );
break;
case _AppPhase.biometricChoice: case _AppPhase.biometricChoice:
return _buildAppShell( homeWidget = _buildAppShell(
home: BiometricChoiceScreen( home: BiometricChoiceScreen(
isBusy: _isUnlocking, isBusy: _isUnlocking,
onEnableBiometrics: () => onEnableBiometrics: () =>
@@ -995,20 +982,30 @@ class _NotesAppState extends State<NotesApp>
_completeBiometricChoice(enableBiometrics: false), _completeBiometricChoice(enableBiometrics: false),
), ),
); );
break;
case _AppPhase.biometricGate: case _AppPhase.biometricGate:
return _buildAppShell( homeWidget = _buildAppShell(
home: BiometricGateScreen( home: BiometricGateScreen(
key: ValueKey<int>(_biometricGateSession), key: ValueKey<int>(_biometricGateSession),
isBusy: _isUnlocking, isBusy: _isUnlocking,
onUnlockRequested: _unlockBiometricGate, onUnlockRequested: _unlockBiometricGate,
), ),
); );
break;
case _AppPhase.notes: case _AppPhase.notes:
if (repository == null) { homeWidget = _buildLoadingScreen();
return _buildLoadingScreen(); break;
}
}
} }
return _buildMainShell(repository); return MaterialApp(
} navigatorKey: _navigatorKey,
title: 'Mis Notas',
debugShowCheckedModeBanner: false,
scaffoldMessengerKey: _scaffoldMessengerKey,
theme: _theme,
home: homeWidget,
);
} }
} }