[package_info] Migrate to null safety (#3398)
diff --git a/packages/package_info/CHANGELOG.md b/packages/package_info/CHANGELOG.md
index f3f7734..91da359 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 eaf2859..5134897 100644
--- a/packages/package_info/lib/package_info.dart
+++ b/packages/package_info/lib/package_info.dart
@@ -24,30 +24,31 @@
/// 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.
diff --git a/packages/package_info/pubspec.yaml b/packages/package_info/pubspec.yaml
index 25e45a6..f575ad1 100644
--- a/packages/package_info/pubspec.yaml
+++ b/packages/package_info/pubspec.yaml
@@ -5,7 +5,7 @@
# 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 @@
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 47d48fd..cb69671 100644
--- a/packages/package_info/test/package_info_test.dart
+++ b/packages/package_info/test/package_info_test.dart
@@ -11,7 +11,7 @@
const MethodChannel channel =
MethodChannel('plugins.flutter.io/package_info');
- List<MethodCall> log;
+ late List<MethodCall> log;
channel.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh
index b43d11c..742487a 100644
--- a/script/nnbd_plugins.sh
+++ b/script/nnbd_plugins.sh
@@ -15,6 +15,7 @@
"google_sign_in"
"local_auth"
"path_provider"
+ "package_info"
"plugin_platform_interface"
"share"
"shared_preferences"