|
| 1 | +import 'dart:async'; |
| 2 | + |
1 | 3 | import 'package:device_info_plus/device_info_plus.dart' as device_info_plus;
|
2 | 4 | import 'package:file_picker/file_picker.dart' as file_picker;
|
3 | 5 | import 'package:firebase_core/firebase_core.dart' as firebase_core;
|
@@ -74,14 +76,20 @@ abstract class ZulipBinding {
|
74 | 76 | _instance = this;
|
75 | 77 | }
|
76 | 78 |
|
77 |
| - /// Prepare the app's [GlobalStore], loading the necessary data. |
| 79 | + /// Get the app's singleton [GlobalStore], |
| 80 | + /// calling [loadGlobalStore] if not already loaded. |
78 | 81 | ///
|
79 |
| - /// Generally the app should call this function only once. |
| 82 | + /// Where possible, use [GlobalStoreWidget.of] to get access to a [GlobalStore]. |
| 83 | + /// Use this method only in contexts like notifications where |
| 84 | + /// a widget tree may not exist. |
| 85 | + Future<GlobalStore> getGlobalStore(); |
| 86 | + |
| 87 | + /// Like [getGlobalStore], but assert this method was not previously called. |
80 | 88 | ///
|
81 |
| - /// This is part of the implementation of [GlobalStoreWidget]. |
82 |
| - /// In application code, use [GlobalStoreWidget.of] to get access |
83 |
| - /// to a [GlobalStore]. |
84 |
| - Future<GlobalStore> loadGlobalStore(); |
| 89 | + /// This is used by the implementation of [GlobalStoreWidget], |
| 90 | + /// so that our test framework code can detect some cases where |
| 91 | + /// a widget test neglects to clean up with `testBinding.reset`. |
| 92 | + Future<GlobalStore> getGlobalStoreUniquely(); |
85 | 93 |
|
86 | 94 | /// Checks whether the platform can launch [url], via package:url_launcher.
|
87 | 95 | ///
|
@@ -324,9 +332,16 @@ class LiveZulipBinding extends ZulipBinding {
|
324 | 332 | }
|
325 | 333 |
|
326 | 334 | @override
|
327 |
| - Future<GlobalStore> loadGlobalStore() { |
328 |
| - return LiveGlobalStore.load(); |
| 335 | + Future<GlobalStore> getGlobalStore() => _globalStore ??= LiveGlobalStore.load(); |
| 336 | + Future<GlobalStore>? _globalStore; |
| 337 | + |
| 338 | + @override |
| 339 | + Future<GlobalStore> getGlobalStoreUniquely() { |
| 340 | + assert(!_debugCalledGetGlobalStoreUniquely); |
| 341 | + assert(_debugCalledGetGlobalStoreUniquely = true); |
| 342 | + return getGlobalStore(); |
329 | 343 | }
|
| 344 | + bool _debugCalledGetGlobalStoreUniquely = false; |
330 | 345 |
|
331 | 346 | @override
|
332 | 347 | Future<bool> canLaunchUrl(Uri url) => url_launcher.canLaunchUrl(url);
|
|
0 commit comments