@@ -3,6 +3,7 @@ import 'package:firebase_core/firebase_core.dart' as firebase_core;
3
3
import 'package:firebase_messaging/firebase_messaging.dart' as firebase_messaging;
4
4
import 'package:flutter/foundation.dart' ;
5
5
import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
6
+ import 'package:package_info_plus/package_info_plus.dart' as package_info_plus;
6
7
import 'package:url_launcher/url_launcher.dart' as url_launcher;
7
8
8
9
import '../host/android_notifications.dart' ;
@@ -81,6 +82,20 @@ abstract class ZulipBinding {
81
82
/// or an error occured while fetching the data.
82
83
BaseDeviceInfo ? get maybeDeviceInfo;
83
84
85
+ /// Provides application package information,
86
+ /// via package:package_info_plus.
87
+ ///
88
+ /// The returned Future resolves to null if an error is
89
+ /// encountered while fetching the data.
90
+ Future <PackageInfo ?> get packageInfo;
91
+
92
+ /// Provides application package information,
93
+ /// via package:package_info_plus.
94
+ ///
95
+ /// May return null if prefetching hasn't completed yet,
96
+ /// or an error occured while fetching the data.
97
+ PackageInfo ? get maybePackageInfo;
98
+
84
99
/// Prepare the app's [GlobalStore] , loading the necessary data.
85
100
///
86
101
/// Generally the app should call this function only once.
@@ -161,6 +176,17 @@ class IosDeviceInfo extends BaseDeviceInfo {
161
176
IosDeviceInfo ({required this .systemVersion});
162
177
}
163
178
179
+ /// Like [package_info_plus.PackageInfo] , but without things we don't use.
180
+ class PackageInfo {
181
+ final String version;
182
+ final String buildNumber;
183
+
184
+ PackageInfo ({
185
+ required this .version,
186
+ required this .buildNumber,
187
+ });
188
+ }
189
+
164
190
/// A concrete binding for use in the live application.
165
191
///
166
192
/// The global store returned by [loadGlobalStore] , and consequently by
@@ -175,6 +201,7 @@ class LiveZulipBinding extends ZulipBinding {
175
201
if (ZulipBinding ._instance == null ) {
176
202
final binding = LiveZulipBinding ();
177
203
binding._deviceInfo = binding._prefetchDeviceInfo ();
204
+ binding._packageInfo = binding._prefetchPackageInfo ();
178
205
}
179
206
return ZulipBinding .instance as LiveZulipBinding ;
180
207
}
@@ -187,6 +214,14 @@ class LiveZulipBinding extends ZulipBinding {
187
214
BaseDeviceInfo ? get maybeDeviceInfo => _maybeDeviceInfo;
188
215
BaseDeviceInfo ? _maybeDeviceInfo;
189
216
217
+ @override
218
+ Future <PackageInfo ?> get packageInfo => _packageInfo;
219
+ late Future <PackageInfo ?> _packageInfo;
220
+
221
+ @override
222
+ PackageInfo ? get maybePackageInfo => _maybePackageInfo;
223
+ PackageInfo ? _maybePackageInfo;
224
+
190
225
Future <BaseDeviceInfo ?> _prefetchDeviceInfo () async {
191
226
try {
192
227
final info = await device_info_plus.DeviceInfoPlugin ().deviceInfo;
@@ -202,6 +237,20 @@ class LiveZulipBinding extends ZulipBinding {
202
237
return _maybeDeviceInfo;
203
238
}
204
239
240
+ Future <PackageInfo ?> _prefetchPackageInfo () async {
241
+ try {
242
+ final info = await package_info_plus.PackageInfo .fromPlatform ();
243
+ _maybePackageInfo = PackageInfo (
244
+ version: info.version,
245
+ buildNumber: info.buildNumber,
246
+ );
247
+ } catch (e) {
248
+ assert (debugLog ('Failed to prefetch package info: $e ' ));
249
+ // TODO(log)
250
+ }
251
+ return _maybePackageInfo;
252
+ }
253
+
205
254
@override
206
255
Future <GlobalStore > loadGlobalStore () {
207
256
return LiveGlobalStore .load ();
0 commit comments