Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[package_info] Migrate to null safety (#3398)
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored Feb 4, 2021
1 parent 9e982cf commit 60fa979
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packages/package_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0-nullsafety

* Migrate to null safety.

## 0.4.3+4

* Ensure `IntegrationTestPlugin` is registered in `example` app, so Firebase Test Lab tests report test results correctly. [Issue](https://github.com/flutter/flutter/issues/74944).
Expand Down
23 changes: 12 additions & 11 deletions packages/package_info/lib/package_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@ class PackageInfo {
/// See [fromPlatform] for the right API to get a [PackageInfo] that's
/// actually populated with real data.
PackageInfo({
this.appName,
this.packageName,
this.version,
this.buildNumber,
required this.appName,
required this.packageName,
required this.version,
required this.buildNumber,
});

static PackageInfo _fromPlatform;
static PackageInfo? _fromPlatform;

/// Retrieves package information from the platform.
/// The result is cached.
static Future<PackageInfo> fromPlatform() async {
if (_fromPlatform != null) {
return _fromPlatform;
}
PackageInfo? packageInfo = _fromPlatform;
if (packageInfo != null) return packageInfo;

final Map<String, dynamic> map =
await _kChannel.invokeMapMethod<String, dynamic>('getAll');
_fromPlatform = PackageInfo(
(await _kChannel.invokeMapMethod<String, dynamic>('getAll'))!;

packageInfo = PackageInfo(
appName: map["appName"],
packageName: map["packageName"],
version: map["version"],
buildNumber: map["buildNumber"],
);
return _fromPlatform;
_fromPlatform = packageInfo;
return packageInfo;
}

/// The app name. `CFBundleDisplayName` on iOS, `application/label` on Android.
Expand Down
6 changes: 3 additions & 3 deletions packages/package_info/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
# 0.4.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.4.3+4
version: 0.5.0-nullsafety

flutter:
plugin:
Expand All @@ -29,8 +29,8 @@ dev_dependencies:
sdk: flutter
integration_test:
path: ../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
2 changes: 1 addition & 1 deletion packages/package_info/test/package_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {

const MethodChannel channel =
MethodChannel('plugins.flutter.io/package_info');
List<MethodCall> log;
late List<MethodCall> log;

channel.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
Expand Down
1 change: 1 addition & 0 deletions script/nnbd_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ readonly NNBD_PLUGINS_LIST=(
"google_sign_in"
"local_auth"
"path_provider"
"package_info"
"plugin_platform_interface"
"share"
"shared_preferences"
Expand Down

0 comments on commit 60fa979

Please sign in to comment.