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

[package_info] Migrate to null safety #3398

Merged
merged 12 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+3

* Update Flutter SDK constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnfield I couldn't find an issue about migrating vm_service to null safe. Do you know if there's any work in the radar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like per dart-lang/sdk#40046 it's been landed. We can look to migrate integration_test and driver.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong. That's for a different part of the SDK. Migration is still ongoing, Dart cl is https://dart-review.googlesource.com/c/sdk/+/156980

Expand Down
4 changes: 2 additions & 2 deletions packages/package_info/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,7 +57,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget _infoTile(String title, String subtitle) {
return ListTile(
title: Text(title),
subtitle: Text(subtitle ?? 'Not set'),
subtitle: Text(subtitle),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/package_info/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ dependencies:
dev_dependencies:
flutter_driver:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which issue did you see that require opting out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an issue with flutter_driver being legacy:

Screen Shot 2021-01-07 at 4 42 03 PM

I wasn't sure when we were planning on migrating test since integration_test isn't null safe yet either.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I believe our solution at this point is not to migrate example to null safety, just the plugin itself, due to integration_test being a blocker.


import 'dart:convert';
import 'dart:io';

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+3
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 @@ -14,6 +14,7 @@ readonly NNBD_PLUGINS_LIST=(
"google_sign_in"
"local_auth"
"path_provider"
"package_info"
"plugin_platform_interface"
"share"
"url_launcher"
Expand Down