Skip to content

Commit 1cf31a4

Browse files
committed
settings [nfc]: Use update method directly on GlobalSettingsStore
This completes the transition to GlobalSettingsStore as the self-contained store for the global settings.
1 parent 793dbc7 commit 1cf31a4

File tree

7 files changed

+15
-20
lines changed

7 files changed

+15
-20
lines changed

lib/model/store.dart

-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ abstract class GlobalStore extends ChangeNotifier {
8686
/// subscribes to changes in the [GlobalSettingsStore].
8787
final GlobalSettingsStore settings;
8888

89-
/// Update the global settings in the store.
90-
// TODO inline this out
91-
Future<void> updateGlobalSettings(GlobalSettingsCompanion data) async {
92-
await settings.update(data);
93-
}
94-
9589
/// A cache of the [Accounts] table in the underlying data store.
9690
final Map<int, Account> _accounts;
9791

lib/widgets/settings.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class _ThemeSetting extends StatelessWidget {
3333
const _ThemeSetting();
3434

3535
void _handleChange(BuildContext context, ThemeSetting? newThemeSetting) {
36-
GlobalStoreWidget.of(context).updateGlobalSettings(
36+
final globalSettings = GlobalStoreWidget.settingsOf(context);
37+
globalSettings.update(
3738
GlobalSettingsCompanion(themeSetting: Value(newThemeSetting)));
3839
}
3940

@@ -60,10 +61,10 @@ class _BrowserPreferenceSetting extends StatelessWidget {
6061
const _BrowserPreferenceSetting();
6162

6263
void _handleChange(BuildContext context, bool newOpenLinksWithInAppBrowser) {
63-
GlobalStoreWidget.of(context).updateGlobalSettings(
64-
GlobalSettingsCompanion(browserPreference: Value(
65-
newOpenLinksWithInAppBrowser ? BrowserPreference.inApp
66-
: BrowserPreference.external)));
64+
final globalSettings = GlobalStoreWidget.settingsOf(context);
65+
globalSettings.update(GlobalSettingsCompanion(browserPreference: Value(
66+
newOpenLinksWithInAppBrowser ? BrowserPreference.inApp
67+
: BrowserPreference.external)));
6768
}
6869

6970
@override

test/model/store_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
final globalStore = eg.globalStore();
3838
check(globalStore).settings.themeSetting.equals(null);
3939

40-
await globalStore.updateGlobalSettings(
40+
await globalStore.settings.update(
4141
GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.dark)));
4242
check(globalStore).settings.themeSetting.equals(ThemeSetting.dark);
4343
});
@@ -48,7 +48,7 @@ void main() {
4848
globalStore.settings.addListener(() => notifyCount++);
4949
check(notifyCount).equals(0);
5050

51-
await globalStore.updateGlobalSettings(
51+
await globalStore.settings.update(
5252
GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.light)));
5353
check(notifyCount).equals(1);
5454
});

test/widgets/content_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ void main() {
801801
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
802802

803803
testWidgets('follow browser preference setting to open URL', (tester) async {
804-
await testBinding.globalStore.updateGlobalSettings(
804+
await testBinding.globalStore.settings.update(
805805
GlobalSettingsData(
806806
browserPreference: BrowserPreference.inApp).toCompanion(false));
807807
await prepare(tester,

test/widgets/settings_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void main() {
5151
testWidgets('smoke', (tester) async {
5252
debugBrightnessOverride = Brightness.light;
5353

54-
await testBinding.globalStore.updateGlobalSettings(
54+
await testBinding.globalStore.settings.update(
5555
GlobalSettingsData(themeSetting: ThemeSetting.light).toCompanion(false));
5656
await prepare(tester);
5757
final element = tester.element(find.byType(SettingsPage));
@@ -101,7 +101,7 @@ void main() {
101101
}
102102

103103
testWidgets('smoke', (tester) async {
104-
await testBinding.globalStore.updateGlobalSettings(
104+
await testBinding.globalStore.settings.update(
105105
GlobalSettingsData(
106106
browserPreference: BrowserPreference.external).toCompanion(false));
107107
await prepare(tester);

test/widgets/store_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void main() {
106106

107107
testWidgets('GlobalStoreWidget.settingsOf updates on settings update', (tester) async {
108108
addTearDown(testBinding.reset);
109-
await testBinding.globalStore.updateGlobalSettings(
109+
await testBinding.globalStore.settings.update(
110110
GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.dark)));
111111

112112
ThemeSetting? themeSetting;
@@ -120,7 +120,7 @@ void main() {
120120
await tester.pump();
121121
check(themeSetting).equals(ThemeSetting.dark);
122122

123-
await testBinding.globalStore.updateGlobalSettings(
123+
await testBinding.globalStore.settings.update(
124124
GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.light)));
125125
await tester.pump();
126126
check(themeSetting).equals(ThemeSetting.light);

test/widgets/theme_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ void main() {
134134
final element = tester.element(find.byType(Placeholder));
135135
check(zulipThemeData(element)).brightness.equals(Brightness.light);
136136

137-
await testBinding.globalStore.updateGlobalSettings(
137+
await testBinding.globalStore.settings.update(
138138
const GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.dark)));
139139
check(zulipThemeData(element)).brightness.equals(Brightness.dark);
140140

141-
await testBinding.globalStore.updateGlobalSettings(
141+
await testBinding.globalStore.settings.update(
142142
const GlobalSettingsCompanion(themeSetting: Value(null)));
143143
check(zulipThemeData(element)).brightness.equals(Brightness.light);
144144
});

0 commit comments

Comments
 (0)