[package_info] Fix pedantic lints (#2319)
This involved internally refactoring how the `PackageInfo.fromPlatform`
code handled futures, but shouldn't change existing functionality.
diff --git a/packages/package_info/CHANGELOG.md b/packages/package_info/CHANGELOG.md
index 90bf0b9..6806df1 100644
--- a/packages/package_info/CHANGELOG.md
+++ b/packages/package_info/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.4.0+12
+
+* Fix pedantic lints. This involved internally refactoring how the
+ `PackageInfo.fromPlatform` code handled futures, but shouldn't change existing
+ functionality.
+
## 0.4.0+11
* Remove AndroidX warnings.
diff --git a/packages/package_info/analysis_options.yaml b/packages/package_info/analysis_options.yaml
deleted file mode 100644
index d4ccef6..0000000
--- a/packages/package_info/analysis_options.yaml
+++ /dev/null
@@ -1,11 +0,0 @@
-# This is a temporary file to allow us to land a new set of linter rules in a
-# series of manageable patches instead of one gigantic PR. It disables some of
-# the new lints that are already failing on this plugin, for this plugin. It
-# should be deleted and the failing lints addressed as soon as possible.
-
-include: ../../analysis_options.yaml
-
-analyzer:
- errors:
- public_member_api_docs: ignore
- unawaited_futures: ignore
diff --git a/packages/package_info/example/lib/main.dart b/packages/package_info/example/lib/main.dart
index 9edbce1..91ed910 100644
--- a/packages/package_info/example/lib/main.dart
+++ b/packages/package_info/example/lib/main.dart
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// ignore_for_file: public_member_api_docs
+
import 'dart:async';
import 'package:flutter/material.dart';
diff --git a/packages/package_info/example/test_driver/package_info_e2e_test.dart b/packages/package_info/example/test_driver/package_info_e2e_test.dart
index ac4ea11..1bcd0d3 100644
--- a/packages/package_info/example/test_driver/package_info_e2e_test.dart
+++ b/packages/package_info/example/test_driver/package_info_e2e_test.dart
@@ -10,6 +10,6 @@
final FlutterDriver driver = await FlutterDriver.connect();
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
- driver.close();
+ await driver.close();
exit(result == 'pass' ? 0 : 1);
}
diff --git a/packages/package_info/lib/package_info.dart b/packages/package_info/lib/package_info.dart
index f1a75d5..eaf2859 100644
--- a/packages/package_info/lib/package_info.dart
+++ b/packages/package_info/lib/package_info.dart
@@ -17,6 +17,12 @@
/// print("Version is: ${packageInfo.version}");
/// ```
class PackageInfo {
+ /// Constructs an instance with the given values for testing. [PackageInfo]
+ /// instances constructed this way won't actually reflect any real information
+ /// from the platform, just whatever was passed in at construction time.
+ ///
+ /// See [fromPlatform] for the right API to get a [PackageInfo] that's
+ /// actually populated with real data.
PackageInfo({
this.appName,
this.packageName,
@@ -24,28 +30,23 @@
this.buildNumber,
});
- static Future<PackageInfo> _fromPlatform;
+ static PackageInfo _fromPlatform;
/// Retrieves package information from the platform.
/// The result is cached.
static Future<PackageInfo> fromPlatform() async {
- if (_fromPlatform == null) {
- final Completer<PackageInfo> completer = Completer<PackageInfo>();
-
- _kChannel.invokeMapMethod<String, dynamic>('getAll').then(
- (dynamic result) {
- final Map<dynamic, dynamic> map = result;
-
- completer.complete(PackageInfo(
- appName: map["appName"],
- packageName: map["packageName"],
- version: map["version"],
- buildNumber: map["buildNumber"],
- ));
- }, onError: completer.completeError);
-
- _fromPlatform = completer.future;
+ if (_fromPlatform != null) {
+ return _fromPlatform;
}
+
+ final Map<String, dynamic> map =
+ await _kChannel.invokeMapMethod<String, dynamic>('getAll');
+ _fromPlatform = PackageInfo(
+ appName: map["appName"],
+ packageName: map["packageName"],
+ version: map["version"],
+ buildNumber: map["buildNumber"],
+ );
return _fromPlatform;
}
diff --git a/packages/package_info/pubspec.yaml b/packages/package_info/pubspec.yaml
index 50712ba..ce61ea0 100644
--- a/packages/package_info/pubspec.yaml
+++ b/packages/package_info/pubspec.yaml
@@ -3,7 +3,7 @@
package, such as CFBundleVersion on iOS or versionCode on Android.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
-version: 0.4.0+11
+version: 0.4.0+12
flutter:
plugin: