File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,13 @@ abstract class ZulipBinding {
83
83
/// a widget tree may not exist.
84
84
Future <GlobalStore > getGlobalStore ();
85
85
86
+ /// Get the app's singleton [GlobalStore] if already loaded, else null.
87
+ ///
88
+ /// Where possible, use [GlobalStoreWidget.of] to get access to a [GlobalStore] .
89
+ /// Use this method only in contexts where getting access to a [BuildContext]
90
+ /// is inconvenient.
91
+ GlobalStore ? getGlobalStoreSync ();
92
+
86
93
/// Like [getGlobalStore] , but assert this method was not previously called.
87
94
///
88
95
/// This is used by the implementation of [GlobalStoreWidget] ,
@@ -333,8 +340,17 @@ class LiveZulipBinding extends ZulipBinding {
333
340
}
334
341
335
342
@override
336
- Future <GlobalStore > getGlobalStore () => _globalStore ?? = LiveGlobalStore .load ();
337
- Future <GlobalStore >? _globalStore;
343
+ Future <GlobalStore > getGlobalStore () {
344
+ return _globalStoreFuture ?? = LiveGlobalStore .load ().then ((store) {
345
+ return _globalStore = store;
346
+ });
347
+ }
348
+
349
+ @override
350
+ GlobalStore ? getGlobalStoreSync () => _globalStore;
351
+
352
+ Future <GlobalStore >? _globalStoreFuture;
353
+ GlobalStore ? _globalStore;
338
354
339
355
@override
340
356
Future <GlobalStore > getGlobalStoreUniquely () {
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ class TestZulipBinding extends ZulipBinding {
104
104
@override
105
105
Future <GlobalStore > getGlobalStore () => Future .value (globalStore);
106
106
107
+ @override
108
+ GlobalStore ? getGlobalStoreSync () => globalStore;
109
+
107
110
@override
108
111
Future <GlobalStore > getGlobalStoreUniquely () {
109
112
assert (() {
You can’t perform that action at this time.
0 commit comments