Skip to content

Commit 2f90d62

Browse files
author
Michael Klimushyn
authored
[package_info] Fix pedantic lints (flutter#2319)
This involved internally refactoring how the `PackageInfo.fromPlatform` code handled futures, but shouldn't change existing functionality.
1 parent dca2f42 commit 2f90d62

File tree

6 files changed

+28
-30
lines changed

6 files changed

+28
-30
lines changed

packages/package_info/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.4.0+12
2+
3+
* Fix pedantic lints. This involved internally refactoring how the
4+
`PackageInfo.fromPlatform` code handled futures, but shouldn't change existing
5+
functionality.
6+
17
## 0.4.0+11
28

39
* Remove AndroidX warnings.

packages/package_info/analysis_options.yaml

-11
This file was deleted.

packages/package_info/example/lib/main.dart

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// ignore_for_file: public_member_api_docs
6+
57
import 'dart:async';
68

79
import 'package:flutter/material.dart';

packages/package_info/example/test_driver/package_info_e2e_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Future<void> main() async {
1010
final FlutterDriver driver = await FlutterDriver.connect();
1111
final String result =
1212
await driver.requestData(null, timeout: const Duration(minutes: 1));
13-
driver.close();
13+
await driver.close();
1414
exit(result == 'pass' ? 0 : 1);
1515
}

packages/package_info/lib/package_info.dart

+18-17
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,36 @@ const MethodChannel _kChannel =
1717
/// print("Version is: ${packageInfo.version}");
1818
/// ```
1919
class PackageInfo {
20+
/// Constructs an instance with the given values for testing. [PackageInfo]
21+
/// instances constructed this way won't actually reflect any real information
22+
/// from the platform, just whatever was passed in at construction time.
23+
///
24+
/// See [fromPlatform] for the right API to get a [PackageInfo] that's
25+
/// actually populated with real data.
2026
PackageInfo({
2127
this.appName,
2228
this.packageName,
2329
this.version,
2430
this.buildNumber,
2531
});
2632

27-
static Future<PackageInfo> _fromPlatform;
33+
static PackageInfo _fromPlatform;
2834

2935
/// Retrieves package information from the platform.
3036
/// The result is cached.
3137
static Future<PackageInfo> fromPlatform() async {
32-
if (_fromPlatform == null) {
33-
final Completer<PackageInfo> completer = Completer<PackageInfo>();
34-
35-
_kChannel.invokeMapMethod<String, dynamic>('getAll').then(
36-
(dynamic result) {
37-
final Map<dynamic, dynamic> map = result;
38-
39-
completer.complete(PackageInfo(
40-
appName: map["appName"],
41-
packageName: map["packageName"],
42-
version: map["version"],
43-
buildNumber: map["buildNumber"],
44-
));
45-
}, onError: completer.completeError);
46-
47-
_fromPlatform = completer.future;
38+
if (_fromPlatform != null) {
39+
return _fromPlatform;
4840
}
41+
42+
final Map<String, dynamic> map =
43+
await _kChannel.invokeMapMethod<String, dynamic>('getAll');
44+
_fromPlatform = PackageInfo(
45+
appName: map["appName"],
46+
packageName: map["packageName"],
47+
version: map["version"],
48+
buildNumber: map["buildNumber"],
49+
);
4950
return _fromPlatform;
5051
}
5152

packages/package_info/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for querying information about the application
33
package, such as CFBundleVersion on iOS or versionCode on Android.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
6-
version: 0.4.0+11
6+
version: 0.4.0+12
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)