forked from firka/firka
add global settingsUpdateNotifier
This helps us update screens when settings change without having to pass around references to setState.
This commit is contained in:
@@ -325,6 +325,8 @@ class SettingsStore {
|
||||
for (var item in items.values) {
|
||||
await item.save(model);
|
||||
}
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
|
||||
Future<void> load(IsarCollection<AppSettingsModel> model) async {
|
||||
@@ -419,6 +421,8 @@ class SettingsGroup implements SettingsItem {
|
||||
}
|
||||
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,6 +457,8 @@ class SettingsSubGroup implements SettingsItem {
|
||||
}
|
||||
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,6 +630,8 @@ class SettingsAppIconPicker implements SettingsItem {
|
||||
v.valueString = icon;
|
||||
|
||||
await model.put(v);
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,6 +671,8 @@ class SettingsBoolean implements SettingsItem {
|
||||
|
||||
await model.put(v);
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,6 +712,8 @@ class SettingsItemsRadio implements SettingsItem {
|
||||
|
||||
await model.put(v);
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,6 +776,8 @@ class SettingsDouble implements SettingsItem {
|
||||
|
||||
await model.put(v);
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,5 +817,7 @@ class SettingsString implements SettingsItem {
|
||||
|
||||
await model.put(v);
|
||||
await postUpdate();
|
||||
|
||||
initData.settingsUpdateNotifier.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:watch_connectivity/watch_connectivity.dart';
|
||||
|
||||
import 'helpers/db/models/homework_cache_model.dart';
|
||||
import 'helpers/update_notifier.dart';
|
||||
import 'l10n/app_localizations.dart';
|
||||
import 'l10n/app_localizations_de.dart';
|
||||
import 'l10n/app_localizations_en.dart';
|
||||
@@ -61,6 +62,7 @@ class AppInitialization {
|
||||
bool hasWatchListener = false;
|
||||
Uint8List? profilePicture;
|
||||
SettingsStore settings;
|
||||
UpdateNotifier settingsUpdateNotifier = UpdateNotifier();
|
||||
AppLocalizations l10n;
|
||||
|
||||
AppInitialization({
|
||||
@@ -159,6 +161,10 @@ Future<AppInitialization> initializeApp() async {
|
||||
l10n: AppLocalizationsHu(),
|
||||
);
|
||||
|
||||
init.settingsUpdateNotifier.addListener(() {
|
||||
debugPrint("Settings updated");
|
||||
});
|
||||
|
||||
await init.settings.load(init.isar.appSettingsModels);
|
||||
initLang(init);
|
||||
init.settings = SettingsStore(init.l10n);
|
||||
|
||||
Reference in New Issue
Block a user