From fec54959db9cd97d2e28aef708dadc0691338ea4 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 4 Feb 2021 15:23:49 -0800 Subject: [PATCH] [package_info] Migrate to null safety (#3398) --- packages/package_info/CHANGELOG.md | 4 ++++ packages/package_info/lib/package_info.dart | 23 ++++++++++--------- packages/package_info/pubspec.yaml | 6 ++--- .../package_info/test/package_info_test.dart | 2 +- script/nnbd_plugins.sh | 1 + 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/package_info/CHANGELOG.md b/packages/package_info/CHANGELOG.md index f3f7734a4082..91da35966283 100644 --- a/packages/package_info/CHANGELOG.md +++ b/packages/package_info/CHANGELOG.md @@ -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). diff --git a/packages/package_info/lib/package_info.dart b/packages/package_info/lib/package_info.dart index eaf28597e56c..51348978ffa5 100644 --- a/packages/package_info/lib/package_info.dart +++ b/packages/package_info/lib/package_info.dart @@ -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 fromPlatform() async { - if (_fromPlatform != null) { - return _fromPlatform; - } + PackageInfo? packageInfo = _fromPlatform; + if (packageInfo != null) return packageInfo; final Map map = - await _kChannel.invokeMapMethod('getAll'); - _fromPlatform = PackageInfo( + (await _kChannel.invokeMapMethod('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. diff --git a/packages/package_info/pubspec.yaml b/packages/package_info/pubspec.yaml index 25e45a6be7bc..f575ad155e4e 100644 --- a/packages/package_info/pubspec.yaml +++ b/packages/package_info/pubspec.yaml @@ -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: @@ -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" diff --git a/packages/package_info/test/package_info_test.dart b/packages/package_info/test/package_info_test.dart index 47d48fde2d2d..cb6967155ca0 100644 --- a/packages/package_info/test/package_info_test.dart +++ b/packages/package_info/test/package_info_test.dart @@ -11,7 +11,7 @@ void main() { const MethodChannel channel = MethodChannel('plugins.flutter.io/package_info'); - List log; + late List log; channel.setMockMethodCallHandler((MethodCall methodCall) async { log.add(methodCall); diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index b43d11c2fe1d..742487ad7bfa 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -15,6 +15,7 @@ readonly NNBD_PLUGINS_LIST=( "google_sign_in" "local_auth" "path_provider" + "package_info" "plugin_platform_interface" "share" "shared_preferences"