Skip to content

Commit 892691e

Browse files
committed
settings [nfc]: Move the settings data out to GlobalSettingsStore
1 parent 8ed6915 commit 892691e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/model/settings.dart

+11-7
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ extension GlobalSettingsHelpers on GlobalSettingsData {
9090
///
9191
/// From UI code, use [GlobalStoreWidget.settingsOf] to get hold of
9292
/// the settings data.
93-
///
94-
/// (At the moment the actual settings data lives on [GlobalStore];
95-
/// but when the settings change, the notification goes to listeners
96-
/// of this class, not [GlobalStore]. Soon the actual data will
97-
/// move to this class too.)
9893
class GlobalSettingsStore extends ChangeNotifier {
99-
// TODO move the actual settings content to this class
94+
GlobalSettingsStore({required GlobalSettingsData data}) : _data = data;
95+
96+
/// A cache of the [GlobalSettingsData] singleton in the underlying data store.
97+
GlobalSettingsData get data => _data;
98+
GlobalSettingsData _data;
10099

101-
void markUpdated() => notifyListeners();
100+
/// (Should only be called by [GlobalStore].)
101+
void update(GlobalSettingsCompanion data) {
102+
// TODO move responsibility for updating the DB to this class too
103+
_data = _data.copyWithCompanion(data);
104+
notifyListeners();
105+
}
102106
}

lib/model/store.dart

+4-7
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,22 @@ abstract class GlobalStore extends ChangeNotifier {
5858
required GlobalSettingsData globalSettings,
5959
required Iterable<Account> accounts,
6060
})
61-
: _globalSettings = globalSettings,
61+
: settingsNotifier = GlobalSettingsStore(data: globalSettings),
6262
_accounts = Map.fromEntries(accounts.map((a) => MapEntry(a.id, a)));
6363

64-
// TODO use this as the actual store
65-
final GlobalSettingsStore settingsNotifier = GlobalSettingsStore();
64+
final GlobalSettingsStore settingsNotifier; // TODO rename as the store
6665

6766
/// A cache of the [GlobalSettingsData] singleton in the underlying data store.
6867
///
6968
/// To be notified for changes to this value, subscribe to [settingsNotifier]
7069
/// (usually by calling [GlobalStoreWidget.settingsOf]).
7170
/// The [GlobalStore] itself will not notify its own listeners.
72-
GlobalSettingsData get globalSettings => _globalSettings;
73-
GlobalSettingsData _globalSettings;
71+
GlobalSettingsData get globalSettings => settingsNotifier.data;
7472

7573
/// Update the global settings in the store.
7674
Future<void> updateGlobalSettings(GlobalSettingsCompanion data) async {
7775
await doUpdateGlobalSettings(data);
78-
_globalSettings = _globalSettings.copyWithCompanion(data);
79-
settingsNotifier.markUpdated();
76+
settingsNotifier.update(data);
8077
}
8178

8279
/// Update the global settings in the underlying data store.

0 commit comments

Comments
 (0)