Skip to content

Commit

Permalink
[Device_info] Replace invokeMethod with invokeMapMethod and some refa…
Browse files Browse the repository at this point in the history
…ctoring around this change. (flutter#1649)
  • Loading branch information
Chris Yang authored May 29, 2019
1 parent af210d0 commit 083699c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
8 changes: 7 additions & 1 deletion packages/device_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 0.4.0
## 0.4.0+2

* Bump minimum Flutter version to 1.5.0.
* Add missing template type parameter to `invokeMethod` calls.
* Replace invokeMethod with invokeMapMethod wherever necessary.

## 0.4.0+1

* Log a more detailed warning at build time about the previous AndroidX
migration.
Expand Down
32 changes: 12 additions & 20 deletions packages/device_info/lib/device_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,18 @@ class DeviceInfoPlugin {
///
/// See: https://developer.android.com/reference/android/os/Build.html
Future<AndroidDeviceInfo> get androidInfo async =>
_cachedAndroidDeviceInfo ??= AndroidDeviceInfo._fromMap(
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod('getAndroidDeviceInfo'));
_cachedAndroidDeviceInfo ??= AndroidDeviceInfo._fromMap(await channel
.invokeMapMethod<String, dynamic>('getAndroidDeviceInfo'));

/// This information does not change from call to call. Cache it.
IosDeviceInfo _cachedIosDeviceInfo;

/// Information derived from `UIDevice`.
///
/// See: https://developer.apple.com/documentation/uikit/uidevice
Future<IosDeviceInfo> get iosInfo async => _cachedIosDeviceInfo ??=
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
IosDeviceInfo._fromMap(await channel.invokeMethod('getIosDeviceInfo'));
Future<IosDeviceInfo> get iosInfo async =>
_cachedIosDeviceInfo ??= IosDeviceInfo._fromMap(
await channel.invokeMapMethod<String, dynamic>('getIosDeviceInfo'));
}

/// Information derived from `android.os.Build`.
Expand Down Expand Up @@ -130,10 +125,10 @@ class AndroidDeviceInfo {
final String androidId;

/// Deserializes from the message received from [_kChannel].
static AndroidDeviceInfo _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
static AndroidDeviceInfo _fromMap(Map<String, dynamic> map) {
return AndroidDeviceInfo._(
version: AndroidBuildVersion._fromMap(map['version']),
version:
AndroidBuildVersion._fromMap(map['version']?.cast<String, dynamic>()),
board: map['board'],
bootloader: map['bootloader'],
brand: map['brand'],
Expand Down Expand Up @@ -202,8 +197,7 @@ class AndroidBuildVersion {
final String securityPatch;

/// Deserializes from the map message received from [_kChannel].
static AndroidBuildVersion _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
static AndroidBuildVersion _fromMap(Map<String, dynamic> map) {
return AndroidBuildVersion._(
baseOS: map['baseOS'],
codename: map['codename'],
Expand Down Expand Up @@ -256,8 +250,7 @@ class IosDeviceInfo {
final IosUtsname utsname;

/// Deserializes from the map message received from [_kChannel].
static IosDeviceInfo _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
static IosDeviceInfo _fromMap(Map<String, dynamic> map) {
return IosDeviceInfo._(
name: map['name'],
systemName: map['systemName'],
Expand All @@ -266,7 +259,7 @@ class IosDeviceInfo {
localizedModel: map['localizedModel'],
identifierForVendor: map['identifierForVendor'],
isPhysicalDevice: map['isPhysicalDevice'] == 'true',
utsname: IosUtsname._fromMap(map['utsname']),
utsname: IosUtsname._fromMap(map['utsname']?.cast<String, dynamic>()),
);
}
}
Expand Down Expand Up @@ -298,8 +291,7 @@ class IosUtsname {
final String machine;

/// Deserializes from the map message received from [_kChannel].
static IosUtsname _fromMap(dynamic message) {
final Map<dynamic, dynamic> map = message;
static IosUtsname _fromMap(Map<String, dynamic> map) {
return IosUtsname._(
sysname: map['sysname'],
nodename: map['nodename'],
Expand Down
4 changes: 2 additions & 2 deletions packages/device_info/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin providing detailed information about the device
(make, model, etc.), and Android or iOS version the app is running on.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/device_info
version: 0.4.0+1
version: 0.4.0+2

flutter:
plugin:
Expand All @@ -17,4 +17,4 @@ dependencies:

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
flutter: ">=1.5.0 <2.0.0"

0 comments on commit 083699c

Please sign in to comment.