From 083699cafcaab82b54a9c3b317db7c2a6157745e Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 29 May 2019 14:37:45 -0700 Subject: [PATCH] [Device_info] Replace invokeMethod with invokeMapMethod and some refactoring around this change. (#1649) --- packages/device_info/CHANGELOG.md | 8 +++++- packages/device_info/lib/device_info.dart | 32 +++++++++-------------- packages/device_info/pubspec.yaml | 4 +-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/device_info/CHANGELOG.md b/packages/device_info/CHANGELOG.md index 0cd39ed0b6eb..c9469d7bd2f1 100644 --- a/packages/device_info/CHANGELOG.md +++ b/packages/device_info/CHANGELOG.md @@ -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. diff --git a/packages/device_info/lib/device_info.dart b/packages/device_info/lib/device_info.dart index 038de10e2268..60cd98f235fa 100644 --- a/packages/device_info/lib/device_info.dart +++ b/packages/device_info/lib/device_info.dart @@ -21,11 +21,8 @@ class DeviceInfoPlugin { /// /// See: https://developer.android.com/reference/android/os/Build.html Future 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('getAndroidDeviceInfo')); /// This information does not change from call to call. Cache it. IosDeviceInfo _cachedIosDeviceInfo; @@ -33,11 +30,9 @@ class DeviceInfoPlugin { /// Information derived from `UIDevice`. /// /// See: https://developer.apple.com/documentation/uikit/uidevice - Future 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 get iosInfo async => + _cachedIosDeviceInfo ??= IosDeviceInfo._fromMap( + await channel.invokeMapMethod('getIosDeviceInfo')); } /// Information derived from `android.os.Build`. @@ -130,10 +125,10 @@ class AndroidDeviceInfo { final String androidId; /// Deserializes from the message received from [_kChannel]. - static AndroidDeviceInfo _fromMap(dynamic message) { - final Map map = message; + static AndroidDeviceInfo _fromMap(Map map) { return AndroidDeviceInfo._( - version: AndroidBuildVersion._fromMap(map['version']), + version: + AndroidBuildVersion._fromMap(map['version']?.cast()), board: map['board'], bootloader: map['bootloader'], brand: map['brand'], @@ -202,8 +197,7 @@ class AndroidBuildVersion { final String securityPatch; /// Deserializes from the map message received from [_kChannel]. - static AndroidBuildVersion _fromMap(dynamic message) { - final Map map = message; + static AndroidBuildVersion _fromMap(Map map) { return AndroidBuildVersion._( baseOS: map['baseOS'], codename: map['codename'], @@ -256,8 +250,7 @@ class IosDeviceInfo { final IosUtsname utsname; /// Deserializes from the map message received from [_kChannel]. - static IosDeviceInfo _fromMap(dynamic message) { - final Map map = message; + static IosDeviceInfo _fromMap(Map map) { return IosDeviceInfo._( name: map['name'], systemName: map['systemName'], @@ -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()), ); } } @@ -298,8 +291,7 @@ class IosUtsname { final String machine; /// Deserializes from the map message received from [_kChannel]. - static IosUtsname _fromMap(dynamic message) { - final Map map = message; + static IosUtsname _fromMap(Map map) { return IosUtsname._( sysname: map['sysname'], nodename: map['nodename'], diff --git a/packages/device_info/pubspec.yaml b/packages/device_info/pubspec.yaml index 762677c6a2e8..fa8ff2346a11 100644 --- a/packages/device_info/pubspec.yaml +++ b/packages/device_info/pubspec.yaml @@ -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 homepage: https://github.com/flutter/plugins/tree/master/packages/device_info -version: 0.4.0+1 +version: 0.4.0+2 flutter: plugin: @@ -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"