feat: Optimize theme data handling and simplify widget structure in NotesApp
This commit is contained in:
+35
-38
@@ -102,6 +102,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
|
||||
setState(() {
|
||||
_themeSeedColor = Color(storedColorValue);
|
||||
_themeData = AppTheme.theme(seedColor: _themeSeedColor);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,10 +116,14 @@ class _NotesAppState extends State<NotesApp>
|
||||
|
||||
setState(() {
|
||||
_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
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
@@ -767,12 +772,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
}
|
||||
|
||||
Widget _buildLoadingScreen() {
|
||||
return MaterialApp(
|
||||
navigatorKey: _navigatorKey,
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: _theme,
|
||||
home: const Scaffold(
|
||||
return const Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -791,19 +791,11 @@ class _NotesAppState extends State<NotesApp>
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppShell({required Widget home}) {
|
||||
return MaterialApp(
|
||||
navigatorKey: _navigatorKey,
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: _scaffoldMessengerKey,
|
||||
theme: _theme,
|
||||
home: home,
|
||||
);
|
||||
return home;
|
||||
}
|
||||
|
||||
Widget _buildMainShell(NoteRepository repository) {
|
||||
@@ -829,13 +821,7 @@ class _NotesAppState extends State<NotesApp>
|
||||
onThemeColorSelected: _setThemeSeedColor,
|
||||
);
|
||||
|
||||
return MaterialApp(
|
||||
navigatorKey: _navigatorKey,
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: _scaffoldMessengerKey,
|
||||
theme: _theme,
|
||||
home: Shortcuts(
|
||||
return Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.f5): const PerformSyncIntent(),
|
||||
},
|
||||
@@ -897,7 +883,6 @@ class _NotesAppState extends State<NotesApp>
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -951,21 +936,22 @@ class _NotesAppState extends State<NotesApp>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isBootstrapping) {
|
||||
return _buildLoadingScreen();
|
||||
}
|
||||
Widget homeWidget;
|
||||
|
||||
if (_isBootstrapping) {
|
||||
homeWidget = _buildLoadingScreen();
|
||||
} else {
|
||||
final NoteRepository? repository = _repository;
|
||||
|
||||
if (repository != null) {
|
||||
return _buildMainShell(repository);
|
||||
}
|
||||
|
||||
homeWidget = _buildMainShell(repository);
|
||||
} else {
|
||||
switch (_phase) {
|
||||
case _AppPhase.loading:
|
||||
return _buildLoadingScreen();
|
||||
homeWidget = _buildLoadingScreen();
|
||||
break;
|
||||
case _AppPhase.access:
|
||||
return _buildAppShell(
|
||||
homeWidget = _buildAppShell(
|
||||
home: VaultAccessScreen(
|
||||
isBusy: _isUnlocking,
|
||||
onCreateAccountPressed: (String email, String password) async {
|
||||
@@ -985,8 +971,9 @@ class _NotesAppState extends State<NotesApp>
|
||||
onContinueWithoutAccount: _enterWithoutAccount,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case _AppPhase.biometricChoice:
|
||||
return _buildAppShell(
|
||||
homeWidget = _buildAppShell(
|
||||
home: BiometricChoiceScreen(
|
||||
isBusy: _isUnlocking,
|
||||
onEnableBiometrics: () =>
|
||||
@@ -995,20 +982,30 @@ class _NotesAppState extends State<NotesApp>
|
||||
_completeBiometricChoice(enableBiometrics: false),
|
||||
),
|
||||
);
|
||||
break;
|
||||
case _AppPhase.biometricGate:
|
||||
return _buildAppShell(
|
||||
homeWidget = _buildAppShell(
|
||||
home: BiometricGateScreen(
|
||||
key: ValueKey<int>(_biometricGateSession),
|
||||
isBusy: _isUnlocking,
|
||||
onUnlockRequested: _unlockBiometricGate,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case _AppPhase.notes:
|
||||
if (repository == null) {
|
||||
return _buildLoadingScreen();
|
||||
homeWidget = _buildLoadingScreen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _buildMainShell(repository);
|
||||
}
|
||||
return MaterialApp(
|
||||
navigatorKey: _navigatorKey,
|
||||
title: 'Mis Notas',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: _scaffoldMessengerKey,
|
||||
theme: _theme,
|
||||
home: homeWidget,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user