@@ -6,6 +6,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
6
6
import 'package:url_launcher/url_launcher.dart' as url_launcher;
7
7
8
8
import '../host/android_notifications.dart' ;
9
+ import '../log.dart' ;
9
10
import '../widgets/store.dart' ;
10
11
import 'store.dart' ;
11
12
@@ -101,8 +102,18 @@ abstract class ZulipBinding {
101
102
/// Provides device and operating system information,
102
103
/// via package:device_info_plus.
103
104
///
105
+ /// The returned Future resolves to null if an error is
106
+ /// encountered while fetching the data.
107
+ ///
104
108
/// This wraps [device_info_plus.DeviceInfoPlugin.deviceInfo] .
105
- Future <BaseDeviceInfo > deviceInfo ();
109
+ Future <BaseDeviceInfo ?> get deviceInfo;
110
+
111
+ /// Provides device and operating system information,
112
+ /// via package:device_info_plus.
113
+ ///
114
+ /// This is the value [deviceInfo] resolved to,
115
+ /// or null if that hasn't resolved yet.
116
+ BaseDeviceInfo ? get syncDeviceInfo;
106
117
107
118
/// Initialize Firebase, to use for notifications.
108
119
///
@@ -161,6 +172,10 @@ class IosDeviceInfo extends BaseDeviceInfo {
161
172
/// Methods wrapping a plugin, like [launchUrl] , invoke the actual
162
173
/// underlying plugin method.
163
174
class LiveZulipBinding extends ZulipBinding {
175
+ LiveZulipBinding () {
176
+ _deviceInfo = _prefetchDeviceInfo ();
177
+ }
178
+
164
179
/// Initialize the binding if necessary, and ensure it is a [LiveZulipBinding] .
165
180
static LiveZulipBinding ensureInitialized () {
166
181
if (ZulipBinding ._instance == null ) {
@@ -196,13 +211,25 @@ class LiveZulipBinding extends ZulipBinding {
196
211
}
197
212
198
213
@override
199
- Future <BaseDeviceInfo > deviceInfo () async {
200
- final deviceInfo = await device_info_plus.DeviceInfoPlugin ().deviceInfo;
201
- return switch (deviceInfo) {
202
- device_info_plus.AndroidDeviceInfo (: var version) => AndroidDeviceInfo (sdkInt: version.sdkInt),
203
- device_info_plus.IosDeviceInfo (: var systemVersion) => IosDeviceInfo (systemVersion: systemVersion),
204
- _ => throw UnimplementedError (),
205
- };
214
+ Future <BaseDeviceInfo ?> get deviceInfo => _deviceInfo;
215
+ late Future <BaseDeviceInfo ?> _deviceInfo;
216
+
217
+ @override
218
+ BaseDeviceInfo ? get syncDeviceInfo => _syncDeviceInfo;
219
+ BaseDeviceInfo ? _syncDeviceInfo;
220
+
221
+ Future <BaseDeviceInfo ?> _prefetchDeviceInfo () async {
222
+ try {
223
+ final info = await device_info_plus.DeviceInfoPlugin ().deviceInfo;
224
+ _syncDeviceInfo = switch (info) {
225
+ device_info_plus.AndroidDeviceInfo (: var version) => AndroidDeviceInfo (sdkInt: version.sdkInt),
226
+ device_info_plus.IosDeviceInfo (: var systemVersion) => IosDeviceInfo (systemVersion: systemVersion),
227
+ _ => throw UnimplementedError (),
228
+ };
229
+ } catch (e, st) {
230
+ assert (debugLog ('Failed to prefetch device info: $e \n $st ' )); // TODO(log)
231
+ }
232
+ return _syncDeviceInfo;
206
233
}
207
234
208
235
@override
0 commit comments