@@ -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' ;
@@ -115,6 +116,22 @@ abstract class ZulipBinding {
115
116
/// or null if that hasn't resolved yet.
116
117
BaseDeviceInfo ? get syncDeviceInfo;
117
118
119
+ /// Provides application package information,
120
+ /// via package:package_info_plus.
121
+ ///
122
+ /// The returned Future resolves to null if an error is
123
+ /// encountered while fetching the data.
124
+ ///
125
+ /// This wraps [package_info_plus.PackageInfo.fromPlatform] .
126
+ Future <PackageInfo ?> get packageInfo;
127
+
128
+ /// Provides application package information,
129
+ /// via package:package_info_plus.
130
+ ///
131
+ /// This is the value [packageInfo] resolved to,
132
+ /// or null if that hasn't resolved yet.
133
+ PackageInfo ? get syncPackageInfo;
134
+
118
135
/// Initialize Firebase, to use for notifications.
119
136
///
120
137
/// This wraps [firebase_core.Firebase.initializeApp] .
@@ -163,6 +180,17 @@ class IosDeviceInfo extends BaseDeviceInfo {
163
180
IosDeviceInfo ({required this .systemVersion});
164
181
}
165
182
183
+ /// Like [package_info_plus.PackageInfo] , but without things we don't use.
184
+ class PackageInfo {
185
+ final String version;
186
+ final String buildNumber;
187
+
188
+ PackageInfo ({
189
+ required this .version,
190
+ required this .buildNumber,
191
+ });
192
+ }
193
+
166
194
/// A concrete binding for use in the live application.
167
195
///
168
196
/// The global store returned by [loadGlobalStore] , and consequently by
@@ -174,6 +202,7 @@ class IosDeviceInfo extends BaseDeviceInfo {
174
202
class LiveZulipBinding extends ZulipBinding {
175
203
LiveZulipBinding () {
176
204
_deviceInfo = _prefetchDeviceInfo ();
205
+ _packageInfo = _prefetchPackageInfo ();
177
206
}
178
207
179
208
/// Initialize the binding if necessary, and ensure it is a [LiveZulipBinding] .
@@ -232,6 +261,27 @@ class LiveZulipBinding extends ZulipBinding {
232
261
return _syncDeviceInfo;
233
262
}
234
263
264
+ @override
265
+ Future <PackageInfo ?> get packageInfo => _packageInfo;
266
+ late Future <PackageInfo ?> _packageInfo;
267
+
268
+ @override
269
+ PackageInfo ? get syncPackageInfo => _syncPackageInfo;
270
+ PackageInfo ? _syncPackageInfo;
271
+
272
+ Future <PackageInfo ?> _prefetchPackageInfo () async {
273
+ try {
274
+ final info = await package_info_plus.PackageInfo .fromPlatform ();
275
+ _syncPackageInfo = PackageInfo (
276
+ version: info.version,
277
+ buildNumber: info.buildNumber,
278
+ );
279
+ } catch (e, st) {
280
+ assert (debugLog ('Failed to prefetch package info: $e \n $st ' )); // TODO(log)
281
+ }
282
+ return _syncPackageInfo;
283
+ }
284
+
235
285
@override
236
286
Future <void > firebaseInitializeApp ({
237
287
required firebase_core.FirebaseOptions options}) {
0 commit comments