manually restart app

This commit is contained in:
lollipopkit
2023-03-21 14:46:30 +08:00
parent 43e32775a3
commit 4cc72328a7
5 changed files with 68 additions and 77 deletions

View File

@@ -19,15 +19,11 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
setTransparentNavigationBar(context); setTransparentNavigationBar(context);
final fontName = getFileName(_setting.fontPath.fetch()); final fontName = getFileName(_setting.fontPath.fetch());
return ValueListenableBuilder<int>( primaryColor = Color(_setting.primaryColor.fetch()!);
valueListenable: _setting.primaryColor.listenable(),
builder: (_, colorValue, __) {
primaryColor = Color(colorValue);
final textStyle = TextStyle(color: primaryColor); final textStyle = TextStyle(color: primaryColor);
final materialColor = primaryColor.materialStateColor; final materialColor = primaryColor.materialStateColor;
final materialColorAlpha = final materialColorAlpha = primaryColor.withOpacity(0.7).materialStateColor;
primaryColor.withOpacity(0.7).materialStateColor;
final fabTheme = final fabTheme =
FloatingActionButtonThemeData(backgroundColor: primaryColor); FloatingActionButtonThemeData(backgroundColor: primaryColor);
final switchTheme = SwitchThemeData( final switchTheme = SwitchThemeData(
@@ -83,7 +79,5 @@ class MyApp extends StatelessWidget {
); );
}, },
); );
},
);
} }
} }

View File

@@ -34,5 +34,5 @@ class SettingStore extends PersistentStore {
StoreProperty<int> get themeMode => property('themeMode', defaultValue: 0); StoreProperty<int> get themeMode => property('themeMode', defaultValue: 0);
/// Font file path /// Font file path
StoreProperty<String> get fontPath => property('fontPath2'); StoreProperty<String> get fontPath => property('fontPath');
} }

View File

@@ -68,7 +68,6 @@ class _MyHomePageState extends State<MyHomePage>
void dispose() { void dispose() {
super.dispose(); super.dispose();
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
_serverProvider.closeServer();
} }
@override @override

View File

@@ -445,8 +445,7 @@ class _ServerPageState extends State<ServerPage>
await GetIt.I.allReady(); await GetIt.I.allReady();
if (_serverProvider.servers.isEmpty) { if (_serverProvider.servers.isEmpty) {
await _serverProvider.loadLocalData(); await _serverProvider.loadLocalData();
await _serverProvider.refreshData(); }
_serverProvider.startAutoRefresh(); _serverProvider.startAutoRefresh();
} }
}
} }

View File

@@ -241,7 +241,7 @@ class _SettingPageState extends State<SettingPage> {
icon: const Icon(Icons.save), icon: const Icon(Icons.save),
onPressed: (() { onPressed: (() {
_setting.primaryColor.put(_selectedColorValue); _setting.primaryColor.put(_selectedColorValue);
setState(() {}); _showRestartSnackbar();
}), }),
); );
} }
@@ -459,18 +459,13 @@ class _SettingPageState extends State<SettingPage> {
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
TextButton( TextButton(
onPressed: () async => pickFontFile(), onPressed: () async => _pickFontFile(),
child: Text(_s.pickFile), child: Text(_s.pickFile),
), ),
TextButton( TextButton(
onPressed: () => setState(() { onPressed: () => setState(() {
_setting.fontPath.delete(); _setting.fontPath.delete();
showSnackBarWithAction( _showRestartSnackbar();
context,
'${_s.success}\n${_s.needRestart}',
_s.restart,
() => rebuildAll(context),
);
}), }),
child: Text(_s.clear), child: Text(_s.clear),
) )
@@ -480,7 +475,7 @@ class _SettingPageState extends State<SettingPage> {
); );
} }
Future<void> pickFontFile() async { Future<void> _pickFontFile() async {
final path = await pickOneFile(); final path = await pickOneFile();
if (path != null) { if (path != null) {
final fontDir_ = await fontDir; final fontDir_ = await fontDir;
@@ -489,14 +484,18 @@ class _SettingPageState extends State<SettingPage> {
await fontFile.copy(newPath); await fontFile.copy(newPath);
_setting.fontPath.put(newPath); _setting.fontPath.put(newPath);
setState(() {}); setState(() {});
_showRestartSnackbar();
return;
}
showSnackBar(context, Text(_s.failed));
}
void _showRestartSnackbar() {
showSnackBarWithAction( showSnackBarWithAction(
context, context,
'${_s.success}\n${_s.needRestart}', '${_s.success}\n${_s.needRestart}',
_s.restart, _s.restart,
() => rebuildAll(context), () => rebuildAll(context),
); );
return;
}
showSnackBar(context, Text(_s.failed));
} }
} }