This repository was archived by the owner on Sep 14, 2023. It is now read-only.
forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpackage_info.dart
More file actions
65 lines (53 loc) · 2.09 KB
/
package_info.dart
File metadata and controls
65 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/services.dart';
const MethodChannel _kChannel =
MethodChannel('plugins.flutter.io/package_info');
/// Application metadata. Provides application bundle information on iOS and
/// application package information on Android.
///
/// ```dart
/// PackageInfo packageInfo = await PackageInfo.fromPlatform()
/// print("Version is: ${packageInfo.version}");
/// ```
class PackageInfo {
/// Constructs an instance with the given values for testing. [PackageInfo]
/// instances constructed this way won't actually reflect any real information
/// from the platform, just whatever was passed in at construction time.
///
/// See [fromPlatform] for the right API to get a [PackageInfo] that's
/// actually populated with real data.
PackageInfo({
required this.appName,
required this.packageName,
required this.version,
required this.buildNumber,
});
static PackageInfo? _fromPlatform;
/// Retrieves package information from the platform.
/// The result is cached.
static Future<PackageInfo> fromPlatform() async {
PackageInfo? packageInfo = _fromPlatform;
if (packageInfo != null) return packageInfo;
final Map<String, dynamic> map =
(await _kChannel.invokeMapMethod<String, dynamic>('getAll'))!;
packageInfo = PackageInfo(
appName: map["appName"],
packageName: map["packageName"],
version: map["version"],
buildNumber: map["buildNumber"],
);
_fromPlatform = packageInfo;
return packageInfo;
}
/// The app name. `CFBundleDisplayName` on iOS, `application/label` on Android.
final String appName;
/// The package name. `bundleIdentifier` on iOS, `getPackageName` on Android.
final String packageName;
/// The package version. `CFBundleShortVersionString` on iOS, `versionName` on Android.
final String version;
/// The build number. `CFBundleVersion` on iOS, `versionCode` on Android.
final String buildNumber;
}