From 0021befcafc034be4b3f931ebe3ff90d6cd6bd40 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 28 Dec 2020 16:22:48 -0500 Subject: [PATCH 1/7] migrate to null safety --- packages/package_info/CHANGELOG.md | 4 ++++ packages/package_info/lib/package_info.dart | 19 +++++++++---------- packages/package_info/pubspec.yaml | 6 +++--- .../package_info/test/package_info_test.dart | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/package_info/CHANGELOG.md b/packages/package_info/CHANGELOG.md index ebb95c1da17e..53cfa13fa2be 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+3 * Update Flutter SDK constraint. diff --git a/packages/package_info/lib/package_info.dart b/packages/package_info/lib/package_info.dart index eaf28597e56c..b734a2c67587 100644 --- a/packages/package_info/lib/package_info.dart +++ b/packages/package_info/lib/package_info.dart @@ -24,30 +24,29 @@ 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; + return _fromPlatform!; } - final Map map = + final Map? map = await _kChannel.invokeMapMethod('getAll'); - _fromPlatform = PackageInfo( - appName: map["appName"], + return _fromPlatform = PackageInfo( + appName: map!["appName"], packageName: map["packageName"], version: map["version"], buildNumber: map["buildNumber"], ); - return _fromPlatform; } /// 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 884a71659a48..327a5d1bb92a 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+3 +version: 0.5.0 flutter: plugin: @@ -29,8 +29,8 @@ dev_dependencies: sdk: flutter integration_test: path: ../integration_test - pedantic: ^1.8.0 + pedantic: ^1.10.0-nullsafety.3 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); From c76b56c18165cba9f4aac73b4ee2b6c3ec09b135 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 6 Jan 2021 13:15:36 -0500 Subject: [PATCH 2/7] update --- .../example/integration_test/package_info_test.dart | 2 ++ packages/package_info/example/lib/main.dart | 2 +- packages/package_info/example/pubspec.yaml | 4 ++-- .../package_info/example/test_driver/integration_test.dart | 2 ++ packages/package_info/pubspec.yaml | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/package_info/example/integration_test/package_info_test.dart b/packages/package_info/example/integration_test/package_info_test.dart index 5038509ec84f..51e8ef15d6e4 100644 --- a/packages/package_info/example/integration_test/package_info_test.dart +++ b/packages/package_info/example/integration_test/package_info_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart = 2.9 + import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; diff --git a/packages/package_info/example/lib/main.dart b/packages/package_info/example/lib/main.dart index 91ed910ef21d..0389badee6a5 100644 --- a/packages/package_info/example/lib/main.dart +++ b/packages/package_info/example/lib/main.dart @@ -25,7 +25,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({Key? key, required this.title}) : super(key: key); final String title; diff --git a/packages/package_info/example/pubspec.yaml b/packages/package_info/example/pubspec.yaml index 605c375e9a8e..66bd1df18a18 100644 --- a/packages/package_info/example/pubspec.yaml +++ b/packages/package_info/example/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: dev_dependencies: flutter_driver: sdk: flutter - pedantic: ^1.8.0 + pedantic: ^1.10.0-nullsafety.3 flutter: uses-material-design: true environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/packages/package_info/example/test_driver/integration_test.dart b/packages/package_info/example/test_driver/integration_test.dart index f532c389a02b..a9f69dfbeb81 100644 --- a/packages/package_info/example/test_driver/integration_test.dart +++ b/packages/package_info/example/test_driver/integration_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart = 2.9 + import 'dart:convert'; import 'dart:io'; diff --git a/packages/package_info/pubspec.yaml b/packages/package_info/pubspec.yaml index 327a5d1bb92a..4e0a99583aff 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.5.0 +version: 0.5.0-nullsafety flutter: plugin: From 1d7b6fc5822c370cffa1799a8d9a078794dce29e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Thu, 7 Jan 2021 15:16:40 -0500 Subject: [PATCH 3/7] use min dependency and fix example warning --- packages/package_info/example/lib/main.dart | 2 +- packages/package_info/example/pubspec.yaml | 2 +- packages/package_info/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/package_info/example/lib/main.dart b/packages/package_info/example/lib/main.dart index 0389badee6a5..ad5be0a814b7 100644 --- a/packages/package_info/example/lib/main.dart +++ b/packages/package_info/example/lib/main.dart @@ -57,7 +57,7 @@ class _MyHomePageState extends State { Widget _infoTile(String title, String subtitle) { return ListTile( title: Text(title), - subtitle: Text(subtitle ?? 'Not set'), + subtitle: Text(subtitle), ); } diff --git a/packages/package_info/example/pubspec.yaml b/packages/package_info/example/pubspec.yaml index 66bd1df18a18..8d07e124262a 100644 --- a/packages/package_info/example/pubspec.yaml +++ b/packages/package_info/example/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: dev_dependencies: flutter_driver: sdk: flutter - pedantic: ^1.10.0-nullsafety.3 + pedantic: ^1.10.0-nullsafety flutter: uses-material-design: true diff --git a/packages/package_info/pubspec.yaml b/packages/package_info/pubspec.yaml index 4e0a99583aff..f575ad155e4e 100644 --- a/packages/package_info/pubspec.yaml +++ b/packages/package_info/pubspec.yaml @@ -29,7 +29,7 @@ dev_dependencies: sdk: flutter integration_test: path: ../integration_test - pedantic: ^1.10.0-nullsafety.3 + pedantic: ^1.10.0-nullsafety environment: sdk: ">=2.12.0-0 <3.0.0" From 08b6bd23bcbfc75740ec661c97d43963bdff83e7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 11 Jan 2021 14:42:32 -0500 Subject: [PATCH 4/7] null check future return value and use local variable --- packages/package_info/lib/package_info.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/package_info/lib/package_info.dart b/packages/package_info/lib/package_info.dart index b734a2c67587..0014a0b47d10 100644 --- a/packages/package_info/lib/package_info.dart +++ b/packages/package_info/lib/package_info.dart @@ -35,14 +35,13 @@ class PackageInfo { /// Retrieves package information from the platform. /// The result is cached. static Future fromPlatform() async { - if (_fromPlatform != null) { - return _fromPlatform!; - } + final PackageInfo? packageInfo = _fromPlatform; + if (packageInfo != null) return packageInfo; - final Map? map = - await _kChannel.invokeMapMethod('getAll'); + final Map map = + (await _kChannel.invokeMapMethod('getAll'))!; return _fromPlatform = PackageInfo( - appName: map!["appName"], + appName: map["appName"], packageName: map["packageName"], version: map["version"], buildNumber: map["buildNumber"], From 7092d001c94f142274a5b5dbece33e6a5b787d71 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Mon, 11 Jan 2021 14:46:11 -0500 Subject: [PATCH 5/7] seperate declaration and return statement --- packages/package_info/lib/package_info.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/package_info/lib/package_info.dart b/packages/package_info/lib/package_info.dart index 0014a0b47d10..51348978ffa5 100644 --- a/packages/package_info/lib/package_info.dart +++ b/packages/package_info/lib/package_info.dart @@ -35,17 +35,20 @@ class PackageInfo { /// Retrieves package information from the platform. /// The result is cached. static Future fromPlatform() async { - final PackageInfo? packageInfo = _fromPlatform; + PackageInfo? packageInfo = _fromPlatform; if (packageInfo != null) return packageInfo; final Map map = (await _kChannel.invokeMapMethod('getAll'))!; - return _fromPlatform = PackageInfo( + + 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. From d2b14663cf208f7cd208e37ea8cb720dbba71429 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 13 Jan 2021 13:15:39 -0500 Subject: [PATCH 6/7] add to nnbd plugins list --- script/nnbd_plugins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 0cab28abe2ab..3a38d46ac761 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -13,6 +13,7 @@ readonly NNBD_PLUGINS_LIST=( "google_sign_in" "local_auth" "path_provider" + "package_info" "plugin_platform_interface" "share" "url_launcher" From bd082149baeb85e0065f66229c644e5f485b2521 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Wed, 3 Feb 2021 18:30:29 -0800 Subject: [PATCH 7/7] reverting example dir back to master --- .../example/integration_test/package_info_test.dart | 2 -- packages/package_info/example/lib/main.dart | 4 ++-- packages/package_info/example/pubspec.yaml | 4 ++-- .../package_info/example/test_driver/integration_test.dart | 2 -- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/package_info/example/integration_test/package_info_test.dart b/packages/package_info/example/integration_test/package_info_test.dart index 51e8ef15d6e4..5038509ec84f 100644 --- a/packages/package_info/example/integration_test/package_info_test.dart +++ b/packages/package_info/example/integration_test/package_info_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.9 - import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; diff --git a/packages/package_info/example/lib/main.dart b/packages/package_info/example/lib/main.dart index ad5be0a814b7..91ed910ef21d 100644 --- a/packages/package_info/example/lib/main.dart +++ b/packages/package_info/example/lib/main.dart @@ -25,7 +25,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + MyHomePage({Key key, this.title}) : super(key: key); final String title; @@ -57,7 +57,7 @@ class _MyHomePageState extends State { Widget _infoTile(String title, String subtitle) { return ListTile( title: Text(title), - subtitle: Text(subtitle), + subtitle: Text(subtitle ?? 'Not set'), ); } diff --git a/packages/package_info/example/pubspec.yaml b/packages/package_info/example/pubspec.yaml index 8d07e124262a..605c375e9a8e 100644 --- a/packages/package_info/example/pubspec.yaml +++ b/packages/package_info/example/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: dev_dependencies: flutter_driver: sdk: flutter - pedantic: ^1.10.0-nullsafety + pedantic: ^1.8.0 flutter: uses-material-design: true environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.1.0 <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/packages/package_info/example/test_driver/integration_test.dart b/packages/package_info/example/test_driver/integration_test.dart index a9f69dfbeb81..f532c389a02b 100644 --- a/packages/package_info/example/test_driver/integration_test.dart +++ b/packages/package_info/example/test_driver/integration_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.9 - import 'dart:convert'; import 'dart:io';