From c4362db88a24eea25ef3a9798199fe27d59616cc Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:04:48 +0200 Subject: [PATCH 01/13] refactor of all dart classes --- .../lib/device_info_plus.dart | 65 +++++++--------- .../lib/src/device_info_plus_linux.dart | 10 ++- .../lib/src/device_info_plus_web.dart | 9 +++ .../lib/src/device_info_plus_windows.dart | 2 + .../lib/src}/model/android_device_info.dart | 43 ++--------- .../lib/src}/model/ios_device_info.dart | 29 ++----- .../lib/src}/model/linux_device_info.dart | 12 ++- .../lib/src}/model/macos_device_info.dart | 33 +++----- .../lib/src}/model/web_browser_info.dart | 10 ++- .../lib/src}/model/windows_device_info.dart | 10 ++- .../test/device_info_plus_web_test.dart | 2 +- .../test/model/android_device_info_fake.dart | 0 .../test/model/android_device_info_test.dart | 4 +- .../test/model/ios_device_info_test.dart | 5 +- .../test/model/linux_device_info_test.dart | 4 +- .../test/model/macos_device_info_test.dart | 41 ++++++++++ .../test/model/web_browser_info_test.dart | 4 +- .../test/model/windows_device_info_test.dart | 4 +- .../device_info_plus_platform_interface.dart | 48 +----------- .../method_channel_device_info.dart | 28 ++----- .../lib/model/base_device_info.dart | 19 ++++- .../test/method_channel_device_info_test.dart | 42 ++-------- .../test/model/macos_device_info_test.dart | 76 ------------------- 23 files changed, 178 insertions(+), 322 deletions(-) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/android_device_info.dart (90%) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/ios_device_info.dart (82%) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/linux_device_info.dart (95%) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/macos_device_info.dart (72%) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/web_browser_info.dart (96%) rename packages/device_info_plus/{device_info_plus_platform_interface/lib => device_info_plus/lib/src}/model/windows_device_info.dart (96%) rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/android_device_info_fake.dart (100%) rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/android_device_info_test.dart (94%) rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/ios_device_info_test.dart (92%) rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/linux_device_info_test.dart (88%) create mode 100644 packages/device_info_plus/device_info_plus/test/model/macos_device_info_test.dart rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/web_browser_info_test.dart (93%) rename packages/device_info_plus/{device_info_plus_platform_interface => device_info_plus}/test/model/windows_device_info_test.dart (94%) delete mode 100644 packages/device_info_plus/device_info_plus_platform_interface/test/model/macos_device_info_test.dart diff --git a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart index de16288738..838de0fb05 100644 --- a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart +++ b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart @@ -6,20 +6,25 @@ import 'dart:async'; import 'dart:io'; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:flutter/foundation.dart'; +import 'src/model/android_device_info.dart'; +import 'src/model/ios_device_info.dart'; +import 'src/model/linux_device_info.dart'; +import 'src/model/macos_device_info.dart'; +import 'src/model/web_browser_info.dart'; +import 'src/model/windows_device_info.dart'; + export 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart' - show - AndroidBuildVersion, - AndroidDeviceInfo, - BaseDeviceInfo, - IosDeviceInfo, - IosUtsname, - LinuxDeviceInfo, - MacOsDeviceInfo, - WindowsDeviceInfo, - WebBrowserInfo, - BrowserName; + show BaseDeviceInfo; + +export 'src/model/android_device_info.dart'; +export 'src/model/ios_device_info.dart'; +export 'src/model/linux_device_info.dart'; +export 'src/model/macos_device_info.dart'; +export 'src/model/web_browser_info.dart'; +export 'src/model/windows_device_info.dart'; export 'src/device_info_plus_linux.dart'; export 'src/device_info_plus_windows.dart' @@ -45,7 +50,8 @@ class DeviceInfoPlugin { /// /// See: https://developer.android.com/reference/android/os/Build.html Future get androidInfo async => - _cachedAndroidDeviceInfo ??= await _platform.androidInfo(); + _cachedAndroidDeviceInfo ??= + AndroidDeviceInfo.fromMap((await _platform.deviceInfo()).data); /// This information does not change from call to call. Cache it. IosDeviceInfo? _cachedIosDeviceInfo; @@ -53,8 +59,8 @@ class DeviceInfoPlugin { /// Information derived from `UIDevice`. /// /// See: https://developer.apple.com/documentation/uikit/uidevice - Future get iosInfo async => - _cachedIosDeviceInfo ??= await _platform.iosInfo(); + Future get iosInfo async => _cachedIosDeviceInfo ??= + IosDeviceInfo.fromMap((await _platform.deviceInfo()).data); /// This information does not change from call to call. Cache it. LinuxDeviceInfo? _cachedLinuxDeviceInfo; @@ -62,47 +68,32 @@ class DeviceInfoPlugin { /// Information derived from `/etc/os-release`. /// /// See: https://www.freedesktop.org/software/systemd/man/os-release.html - Future get linuxInfo async => - _cachedLinuxDeviceInfo ??= await _platform.linuxInfo(); + Future get linuxInfo async => _cachedLinuxDeviceInfo ??= + await _platform.deviceInfo() as LinuxDeviceInfo; /// This information does not change from call to call. Cache it. WebBrowserInfo? _cachedWebBrowserInfo; /// Information derived from `Navigator`. Future get webBrowserInfo async => - _cachedWebBrowserInfo ??= await _platform.webBrowserInfo(); + _cachedWebBrowserInfo ??= await _platform.deviceInfo() as WebBrowserInfo; /// This information does not change from call to call. Cache it. MacOsDeviceInfo? _cachedMacosDeviceInfo; /// Returns device information for macos. Information sourced from Sysctl. - Future get macOsInfo async => - _cachedMacosDeviceInfo ??= await _platform.macosInfo(); + Future get macOsInfo async => _cachedMacosDeviceInfo ??= + MacOsDeviceInfo.fromMap((await _platform.deviceInfo()).data); WindowsDeviceInfo? _cachedWindowsDeviceInfo; /// Returns device information for Windows. Future get windowsInfo async => - _cachedWindowsDeviceInfo ??= await _platform.windowsInfo()!; + _cachedWindowsDeviceInfo ??= + await _platform.deviceInfo() as WindowsDeviceInfo; /// Returns device information for the current platform. Future get deviceInfo async { - if (kIsWeb) { - return webBrowserInfo; - } else { - if (Platform.isAndroid) { - return androidInfo; - } else if (Platform.isIOS) { - return iosInfo; - } else if (Platform.isLinux) { - return linuxInfo; - } else if (Platform.isMacOS) { - return macOsInfo; - } else if (Platform.isWindows) { - return windowsInfo; - } - } - - throw UnsupportedError('Unsupported platform'); + return _platform.deviceInfo(); } } diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart index d4897597cf..819c1a29f6 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart @@ -1,10 +1,14 @@ import 'dart:async'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:meta/meta.dart'; +import 'model/linux_device_info.dart'; + /// See [DeviceInfoPlatform] class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform { /// Register this dart class as the platform implementation for linux @@ -20,10 +24,14 @@ class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform { : _fileSystem = fileSystem ?? const LocalFileSystem(); @override - Future linuxInfo() async { + Future deviceInfo() async { return _cache ??= await _getInfo(); } + Future linuxInfo() async { + return deviceInfo as LinuxDeviceInfo; + } + Future _getInfo() async { final os = await _getOsRelease() ?? {}; final lsb = await _getLsbRelease() ?? {}; diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart index cd33c32f9b..d8d0bebb62 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart @@ -4,6 +4,8 @@ import 'dart:html' as html show window, Navigator; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'model/web_browser_info.dart'; + /// The web implementation of the BatteryPlusPlatform of the BatteryPlus plugin. class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform { /// Constructs a DeviceInfoPlusPlugin. @@ -42,3 +44,10 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform { ); } } + + +extension WebDeviceInfoPlugin on DeviceInfoPlatform { + Future webInfo() async { + return deviceInfo as WebBrowserInfo; + } +} diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart index 254c460e1e..b5cabe1a66 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart @@ -9,6 +9,8 @@ import 'package:ffi/ffi.dart'; import 'package:meta/meta.dart'; import 'package:win32/win32.dart'; +import 'model/windows_device_info.dart'; + /// The Windows implementation of [DeviceInfoPlatform]. class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform { /// Register this dart class as the platform implementation for windows diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/android_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart similarity index 90% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/android_device_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart index 6fd1fe7b1e..a8ad010b52 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/android_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/android_device_info.dart @@ -3,14 +3,14 @@ // found in the LICENSE file. import 'dart:math' as math show sqrt; -import 'base_device_info.dart'; +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Information derived from `android.os.Build`. /// /// See: https://developer.android.com/reference/android/os/Build.html -class AndroidDeviceInfo implements BaseDeviceInfo { - /// Android device Info class. - AndroidDeviceInfo({ +class AndroidDeviceInfo extends BaseDeviceInfo { + AndroidDeviceInfo._({ + required Map data, required this.version, required this.board, required this.bootloader, @@ -35,7 +35,8 @@ class AndroidDeviceInfo implements BaseDeviceInfo { }) : supported32BitAbis = List.unmodifiable(supported32BitAbis), supported64BitAbis = List.unmodifiable(supported64BitAbis), supportedAbis = List.unmodifiable(supportedAbis), - systemFeatures = List.unmodifiable(systemFeatures); + systemFeatures = List.unmodifiable(systemFeatures), + super(data); /// Android operating system version values derived from `android.os.Build.VERSION`. final AndroidBuildVersion version; @@ -116,38 +117,10 @@ class AndroidDeviceInfo implements BaseDeviceInfo { /// Information about the current android display. final AndroidDisplayMetrics displayMetrics; - /// Serializes [AndroidDeviceInfo] to map. - @Deprecated('[toMap] method will be discontinued') - @override - Map toMap() { - return { - 'id': id, - 'host': host, - 'tags': tags, - 'type': type, - 'model': model, - 'board': board, - 'brand': brand, - 'device': device, - 'product': product, - 'display': display, - 'hardware': hardware, - 'bootloader': bootloader, - 'version': version.toMap(), - 'fingerprint': fingerprint, - 'manufacturer': manufacturer, - 'supportedAbis': supportedAbis, - 'systemFeatures': systemFeatures, - 'isPhysicalDevice': isPhysicalDevice, - 'supported32BitAbis': supported32BitAbis, - 'supported64BitAbis': supported64BitAbis, - 'displayMetrics': displayMetrics.toMap(), - }; - } - /// Deserializes from the message received from [_kChannel]. static AndroidDeviceInfo fromMap(Map map) { - return AndroidDeviceInfo( + return AndroidDeviceInfo._( + data: map, version: AndroidBuildVersion._fromMap( map['version']?.cast() ?? {}), board: map['board'], diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/ios_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart similarity index 82% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/ios_device_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart index f250492472..fd868bc35b 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/ios_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart @@ -2,14 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'base_device_info.dart'; + +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Information derived from `UIDevice`. /// /// See: https://developer.apple.com/documentation/uikit/uidevice -class IosDeviceInfo implements BaseDeviceInfo { +class IosDeviceInfo extends BaseDeviceInfo { /// IOS device info class. - const IosDeviceInfo({ + IosDeviceInfo._({ + required Map data, this.name, this.systemName, this.systemVersion, @@ -18,7 +20,7 @@ class IosDeviceInfo implements BaseDeviceInfo { this.identifierForVendor, required this.isPhysicalDevice, required this.utsname, - }); + }): super(data); /// Device name. final String? name; @@ -46,7 +48,8 @@ class IosDeviceInfo implements BaseDeviceInfo { /// Deserializes from the map message received from [_kChannel]. static IosDeviceInfo fromMap(Map map) { - return IosDeviceInfo( + return IosDeviceInfo._( + data: map, name: map['name'], systemName: map['systemName'], systemVersion: map['systemVersion'], @@ -58,22 +61,6 @@ class IosDeviceInfo implements BaseDeviceInfo { IosUtsname._fromMap(map['utsname']?.cast() ?? {}), ); } - - /// Serializes [IosDeviceInfo] to a map. - @Deprecated('[toMap] method will be discontinued') - @override - Map toMap() { - return { - 'name': name, - 'model': model, - 'systemName': systemName, - 'utsname': utsname._toMap(), - 'systemVersion': systemVersion, - 'localizedModel': localizedModel, - 'identifierForVendor': identifierForVendor, - 'isPhysicalDevice': isPhysicalDevice.toString(), - }; - } } /// Information derived from `utsname`. diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/linux_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart similarity index 95% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/linux_device_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart index 1021ef3cdc..428cc902b8 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/linux_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'base_device_info.dart'; + +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Device information for a Linux system. /// @@ -139,8 +140,11 @@ class LinuxDeviceInfo implements BaseDeviceInfo { /// decoded from hexadecimal, this corresponds to a 16-byte/128-bit value. final String? machineId; - /// Serializes [LinuxDeviceInfo] to a map. - @Deprecated('[toMap] method will be discontinued') + @override + // ignore: deprecated_member_use_from_same_package + Map get data => toMap(); + + @Deprecated('Use [data] getter instead') @override Map toMap() { return { @@ -158,3 +162,5 @@ class LinuxDeviceInfo implements BaseDeviceInfo { }; } } + + diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/macos_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart similarity index 72% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/macos_device_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart index 4f535e376f..5a84b55aac 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/macos_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'base_device_info.dart'; + +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Object encapsulating MACOS device information. -class MacOsDeviceInfo implements BaseDeviceInfo { +class MacOsDeviceInfo extends BaseDeviceInfo { /// Constructs a MacOsDeviceInfo. - const MacOsDeviceInfo({ + MacOsDeviceInfo._({ + required Map data, required this.computerName, required this.hostName, required this.arch, @@ -18,7 +20,7 @@ class MacOsDeviceInfo implements BaseDeviceInfo { required this.memorySize, required this.cpuFrequency, required this.systemGUID, - }); + }): super(data); /// Name given to the local machine. final String computerName; @@ -54,27 +56,10 @@ class MacOsDeviceInfo implements BaseDeviceInfo { /// Device GUID final String? systemGUID; - /// Serializes [MacOsDeviceInfo] to map. - @Deprecated('[toMap] method will be discontinued') - @override - Map toMap() { - return { - 'arch': arch, - 'model': model, - 'hostName': hostName, - 'osRelease': osRelease, - 'activeCPUs': activeCPUs, - 'memorySize': memorySize, - 'cpuFrequency': cpuFrequency, - 'computerName': computerName, - 'kernelVersion': kernelVersion, - 'systemGUID': systemGUID, - }; - } - /// Constructs a [MacOsDeviceInfo] from a Map of dynamic. - static MacOsDeviceInfo fromMap(Map map) { - return MacOsDeviceInfo( + static MacOsDeviceInfo fromMap(Map map) { + return MacOsDeviceInfo._( + data: map, computerName: map['computerName'], hostName: map['hostName'], arch: map['arch'], diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/web_browser_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart similarity index 96% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/web_browser_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart index c4e3e6cae9..b044c914ec 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/web_browser_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'base_device_info.dart'; + +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// List of supported browsers enum BrowserName { @@ -128,8 +129,7 @@ class WebBrowserInfo implements BaseDeviceInfo { ); } - /// Serializes [WebBrowserInfo] to a map. - @Deprecated('[toMap] method will be discontinued') + @Deprecated('use [data] instead') @override Map toMap() { return { @@ -182,4 +182,8 @@ class WebBrowserInfo implements BaseDeviceInfo { return BrowserName.unknown; } } + + @override + // ignore: deprecated_member_use_from_same_package + Map get data => toMap(); } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/windows_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart similarity index 96% rename from packages/device_info_plus/device_info_plus_platform_interface/lib/model/windows_device_info.dart rename to packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart index 1b5dac3239..d6819beadb 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/windows_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart @@ -4,7 +4,8 @@ import 'dart:typed_data'; -import 'base_device_info.dart'; +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; + /// Object encapsulating WINDOWS device information. class WindowsDeviceInfo implements BaseDeviceInfo { @@ -136,8 +137,7 @@ class WindowsDeviceInfo implements BaseDeviceInfo { /// Value of `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQMClient\MachineId` registry key. final String deviceId; - /// Serializes [WindowsDeviceInfo] to a map. - @Deprecated('[toMap] method will be discontinued') + @Deprecated('use [data] instead') @override Map toMap() { return { @@ -168,4 +168,8 @@ class WindowsDeviceInfo implements BaseDeviceInfo { 'deviceId': deviceId, }; } + + @override + // ignore: deprecated_member_use_from_same_package + Map get data => toMap(); } diff --git a/packages/device_info_plus/device_info_plus/test/device_info_plus_web_test.dart b/packages/device_info_plus/device_info_plus/test/device_info_plus_web_test.dart index bdb80de575..1fb26eb784 100644 --- a/packages/device_info_plus/device_info_plus/test/device_info_plus_web_test.dart +++ b/packages/device_info_plus/device_info_plus/test/device_info_plus_web_test.dart @@ -1,4 +1,4 @@ -import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; +import 'package:device_info_plus/src/model/web_browser_info.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/android_device_info_fake.dart b/packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart similarity index 100% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/android_device_info_fake.dart rename to packages/device_info_plus/device_info_plus/test/model/android_device_info_fake.dart diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/android_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart similarity index 94% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/android_device_info_test.dart rename to packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart index fd072c418c..59edfbe8c9 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/android_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/android_device_info_test.dart @@ -1,6 +1,6 @@ // ignore_for_file: deprecated_member_use_from_same_package -import 'package:device_info_plus_platform_interface/model/android_device_info.dart'; +import 'package:device_info_plus/src/model/android_device_info.dart'; import 'package:flutter_test/flutter_test.dart'; import 'android_device_info_fake.dart'; @@ -48,7 +48,7 @@ void main() { final androidDeviceInfo = AndroidDeviceInfo.fromMap(fakeAndroidDeviceInfo); - expect(androidDeviceInfo.toMap(), fakeAndroidDeviceInfo); + expect(androidDeviceInfo.data, fakeAndroidDeviceInfo); }); }); }); diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/ios_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/ios_device_info_test.dart similarity index 92% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/ios_device_info_test.dart rename to packages/device_info_plus/device_info_plus/test/model/ios_device_info_test.dart index 33a40c4310..4c5ad3a265 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/ios_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/ios_device_info_test.dart @@ -1,6 +1,6 @@ // ignore_for_file: deprecated_member_use_from_same_package -import 'package:device_info_plus_platform_interface/model/ios_device_info.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -42,8 +42,7 @@ void main() { test('toMap should return map with correct key and map', () { final iosDeviceInfo = IosDeviceInfo.fromMap(iosDeviceInfoMap); - - expect(iosDeviceInfo.toMap(), iosDeviceInfoMap); + expect(iosDeviceInfo.data, iosDeviceInfoMap); }); }); }); diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/linux_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/linux_device_info_test.dart similarity index 88% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/linux_device_info_test.dart rename to packages/device_info_plus/device_info_plus/test/model/linux_device_info_test.dart index 32fd7b64de..1d4b21e903 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/linux_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/linux_device_info_test.dart @@ -1,6 +1,6 @@ // ignore_for_file: deprecated_member_use_from_same_package -import 'package:device_info_plus_platform_interface/model/linux_device_info.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -20,7 +20,7 @@ void main() { machineId: 'machineId', ); - expect(linuxDeviceInfo.toMap(), { + expect(linuxDeviceInfo.data, { 'name': 'name', 'version': 'version', 'id': 'id', diff --git a/packages/device_info_plus/device_info_plus/test/model/macos_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/macos_device_info_test.dart new file mode 100644 index 0000000000..3969da3181 --- /dev/null +++ b/packages/device_info_plus/device_info_plus/test/model/macos_device_info_test.dart @@ -0,0 +1,41 @@ +// ignore_for_file: deprecated_member_use_from_same_package + +import 'package:device_info_plus/device_info_plus.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('$MacOsDeviceInfo', () { + group('fromMap | data', () { + const macosDeviceInfoMap = { + 'arch': 'arch', + 'model': 'model', + 'activeCPUs': 4, + 'memorySize': 16, + 'cpuFrequency': 2, + 'hostName': 'hostName', + 'osRelease': 'osRelease', + 'computerName': 'computerName', + 'kernelVersion': 'kernelVersion', + 'systemGUID': null, + }; + + test('fromMap should return $MacOsDeviceInfo with correct values', () { + final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); + + expect(macosDeviceInfo.arch, 'arch'); + expect(macosDeviceInfo.model, 'model'); + expect(macosDeviceInfo.activeCPUs, 4); + expect(macosDeviceInfo.memorySize, 16); + expect(macosDeviceInfo.cpuFrequency, 2); + expect(macosDeviceInfo.hostName, 'hostName'); + expect(macosDeviceInfo.osRelease, 'osRelease'); + expect(macosDeviceInfo.systemGUID, isNull); + }); + + test('toMap should return map with correct key and map', () { + final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); + expect(macosDeviceInfo.data, macosDeviceInfoMap); + }); + }); + }); +} diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/web_browser_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/web_browser_info_test.dart similarity index 93% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/web_browser_info_test.dart rename to packages/device_info_plus/device_info_plus/test/model/web_browser_info_test.dart index 0f3bd7d43b..51e5fa6a0f 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/web_browser_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/web_browser_info_test.dart @@ -1,6 +1,6 @@ // ignore_for_file: deprecated_member_use_from_same_package -import 'package:device_info_plus_platform_interface/model/web_browser_info.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -46,7 +46,7 @@ void main() { test('toMap should return map with correct key and map', () { final webBrowserInfo = WebBrowserInfo.fromMap(webBrowserInfoMap); - expect(webBrowserInfo.toMap(), webBrowserInfoMap); + expect(webBrowserInfo.data, webBrowserInfoMap); }); }); }); diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/windows_device_info_test.dart b/packages/device_info_plus/device_info_plus/test/model/windows_device_info_test.dart similarity index 94% rename from packages/device_info_plus/device_info_plus_platform_interface/test/model/windows_device_info_test.dart rename to packages/device_info_plus/device_info_plus/test/model/windows_device_info_test.dart index fba1a415b6..ee452ca81f 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/windows_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus/test/model/windows_device_info_test.dart @@ -1,7 +1,7 @@ // ignore_for_file: deprecated_member_use_from_same_package import 'dart:typed_data'; -import 'package:device_info_plus_platform_interface/model/windows_device_info.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -35,7 +35,7 @@ void main() { deviceId: 'deviceId', ); - expect(windowsDeviceInfo.toMap(), { + expect(windowsDeviceInfo.data, { 'computerName': 'computerName', 'numberOfCores': 4, 'systemMemoryInMegabytes': 16, diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/device_info_plus_platform_interface.dart b/packages/device_info_plus/device_info_plus_platform_interface/lib/device_info_plus_platform_interface.dart index e8808a7f53..72acd360c6 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/device_info_plus_platform_interface.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/lib/device_info_plus_platform_interface.dart @@ -4,23 +4,12 @@ import 'dart:async'; -import 'package:device_info_plus_platform_interface/model/macos_device_info.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'method_channel/method_channel_device_info.dart'; -import 'model/android_device_info.dart'; -import 'model/ios_device_info.dart'; -import 'model/linux_device_info.dart'; -import 'model/web_browser_info.dart'; -import 'model/windows_device_info.dart'; +import 'model/base_device_info.dart'; -export 'model/android_device_info.dart'; export 'model/base_device_info.dart'; -export 'model/ios_device_info.dart'; -export 'model/linux_device_info.dart'; -export 'model/macos_device_info.dart'; -export 'model/web_browser_info.dart'; -export 'model/windows_device_info.dart'; /// The interface that implementations of device_info must implement. /// @@ -49,39 +38,8 @@ abstract class DeviceInfoPlatform extends PlatformInterface { _instance = instance; } - // Gets the Android device information. // ignore: public_member_api_docs - Future androidInfo() { - throw UnimplementedError('androidInfo() has not been implemented.'); - } - - // Gets the iOS device information. - // ignore: public_member_api_docs - Future iosInfo() { - throw UnimplementedError('iosInfo() has not been implemented.'); - } - - // Gets the Linux device information. - // ignore: public_member_api_docs - Future linuxInfo() { - throw UnimplementedError('linuxInfo() has not been implemented.'); - } - - // Gets the web browser information. - // ignore: public_member_api_docs - Future webBrowserInfo() { - throw UnimplementedError('webBrowserInfo() has not been implemented.'); - } - - // Gets the Macos device information. - // ignore: public_member_api_docs - Future macosInfo() { - throw UnimplementedError('macosInfo() has not been implemented.'); - } - - // Gets the Windows device information - // ignore: public_member_api_docs - Future? windowsInfo() { - throw UnimplementedError('windowsInfo() has not been implemented.'); + Future deviceInfo() { + throw UnimplementedError('deviceInfo() has not been implemented.'); } } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart index 3628336983..3b4fea826d 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; @@ -12,29 +13,10 @@ class MethodChannelDeviceInfo extends DeviceInfoPlatform { MethodChannel channel = const MethodChannel('dev.fluttercommunity.plus/device_info'); - // Method channel for Android devices + // Generic method channel for all devices @override - Future androidInfo() async { - return AndroidDeviceInfo.fromMap( - (await channel.invokeMethod('getAndroidDeviceInfo')) - .cast(), - ); - } - - // Method channel for iOS devices - @override - Future iosInfo() async { - return IosDeviceInfo.fromMap( - (await channel.invokeMethod('getIosDeviceInfo')).cast(), - ); - } - - // Method channel for macOS devices - @override - Future macosInfo() async { - return MacOsDeviceInfo.fromMap( - (await channel.invokeMethod('getMacosDeviceInfo')) - .cast(), - ); + Future deviceInfo() async { + return BaseDeviceInfo((await channel.invokeMethod('getDeviceInfo')) + .cast()); } } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/base_device_info.dart b/packages/device_info_plus/device_info_plus_platform_interface/lib/model/base_device_info.dart index 919f5b5fb8..38d5a076f7 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/model/base_device_info.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/lib/model/base_device_info.dart @@ -1,6 +1,17 @@ /// The base class for platform's device info. -abstract class BaseDeviceInfo { - /// Serializes device info properties to a map. - @Deprecated('[toMap] method will be discontinued') - Map toMap(); +class BaseDeviceInfo { + BaseDeviceInfo(this.data); + + /// Device information data + /// Warning: The returned Map may not be JSON-encodable. + final Map data; + + /// For legacy purposes + @Deprecated('Use [data] getter instead') + Map toMap() => data; + + @override + String toString() { + return 'BaseDeviceInfo{data: $data}'; + } } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart b/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart index 3eefe27ce1..e0a206c939 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:device_info_plus_platform_interface/method_channel/method_channel_device_info.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:device_info_plus_platform_interface/method_channel/method_channel_device_info.dart'; - -import 'model/android_device_info_fake.dart'; +import '../../device_info_plus/test/model/android_device_info_fake.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -21,44 +20,17 @@ void main() { methodChannelDeviceInfo.channel .setMockMethodCallHandler((MethodCall methodCall) async { switch (methodCall.method) { - case 'getAndroidDeviceInfo': - return fakeAndroidDeviceInfo; - case 'getIosDeviceInfo': - return ({ - 'name': 'iPhone 10', - }); - case 'getMacosDeviceInfo': - return ({ - 'arch': '', - 'model': 'MacBookPro', - 'activeCPUs': 0, - 'memorySize': 0, - 'cpuFrequency': 0, - 'hostName': '', - 'osRelease': '', - 'computerName': '', - 'kernelVersion': '', - 'systemGUID': null, - }); + case 'getDeviceInfo': + return {'device_info': 'is_fake'}; default: return null; } }); }); - test('androidInfo', () async { - final result = await methodChannelDeviceInfo.androidInfo(); - expect(result.brand, 'Google'); - }); - - test('iosInfo', () async { - final result = await methodChannelDeviceInfo.iosInfo(); - expect(result.name, 'iPhone 10'); - }); - - test('macosInfo', () async { - final result = await methodChannelDeviceInfo.macosInfo(); - expect(result.model, 'MacBookPro'); + test('deviceInfo', () async { + final result = await methodChannelDeviceInfo.deviceInfo(); + expect(result.data['device_info'], 'is_fake'); }); }); } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/model/macos_device_info_test.dart b/packages/device_info_plus/device_info_plus_platform_interface/test/model/macos_device_info_test.dart deleted file mode 100644 index 54c3d1090f..0000000000 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/model/macos_device_info_test.dart +++ /dev/null @@ -1,76 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'package:device_info_plus_platform_interface/model/macos_device_info.dart'; -import 'package:flutter_test/flutter_test.dart'; - -void main() { - group('$MacOsDeviceInfo', () { - group('fromMap | toMap', () { - const macosDeviceInfoMap = { - 'arch': 'arch', - 'model': 'model', - 'activeCPUs': 4, - 'memorySize': 16, - 'cpuFrequency': 2, - 'hostName': 'hostName', - 'osRelease': 'osRelease', - 'computerName': 'computerName', - 'kernelVersion': 'kernelVersion', - 'systemGUID': null, - }; - - test('fromMap should return $MacOsDeviceInfo with correct values', () { - final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); - - expect(macosDeviceInfo.arch, 'arch'); - expect(macosDeviceInfo.model, 'model'); - expect(macosDeviceInfo.activeCPUs, 4); - expect(macosDeviceInfo.memorySize, 16); - expect(macosDeviceInfo.cpuFrequency, 2); - expect(macosDeviceInfo.hostName, 'hostName'); - expect(macosDeviceInfo.osRelease, 'osRelease'); - expect(macosDeviceInfo.systemGUID, isNull); - }); - - test('toMap should return map with correct key and map', () { - final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); - - expect(macosDeviceInfo.toMap(), macosDeviceInfoMap); - }); - }); - - group('fromMap | toMap', () { - const macosDeviceInfoMap = { - 'arch': 'arch', - 'model': 'model', - 'activeCPUs': 4, - 'memorySize': 16, - 'cpuFrequency': 2, - 'hostName': 'hostName', - 'osRelease': 'osRelease', - 'computerName': 'computerName', - 'kernelVersion': 'kernelVersion', - 'systemGUID': 'systemGUID', - }; - - test('fromMap should return $MacOsDeviceInfo with correct values', () { - final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); - - expect(macosDeviceInfo.arch, 'arch'); - expect(macosDeviceInfo.model, 'model'); - expect(macosDeviceInfo.activeCPUs, 4); - expect(macosDeviceInfo.memorySize, 16); - expect(macosDeviceInfo.cpuFrequency, 2); - expect(macosDeviceInfo.hostName, 'hostName'); - expect(macosDeviceInfo.osRelease, 'osRelease'); - expect(macosDeviceInfo.systemGUID, 'systemGUID'); - }); - - test('toMap should return map with correct key and map', () { - final macosDeviceInfo = MacOsDeviceInfo.fromMap(macosDeviceInfoMap); - - expect(macosDeviceInfo.toMap(), macosDeviceInfoMap); - }); - }); - }); -} From 00586a5789aeb6015668c5a44630a8f0e3e7cdfc Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:06:03 +0200 Subject: [PATCH 02/13] renamed native methods to getDeviceInfo --- .../fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt | 2 +- .../device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m | 2 +- .../macos/Classes/DeviceInfoPlusMacosPlugin.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt index 4c128f5cda..fec819ba8c 100644 --- a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt +++ b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt @@ -21,7 +21,7 @@ internal class MethodCallHandlerImpl( ) : MethodCallHandler { override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { - if (call.method.equals("getAndroidDeviceInfo")) { + if (call.method.equals("getDeviceInfo")) { val build: MutableMap = HashMap() build["board"] = Build.BOARD diff --git a/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m b/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m index 1250bae904..f6ed8af02e 100644 --- a/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m +++ b/packages/device_info_plus/device_info_plus/ios/Classes/FLTDeviceInfoPlusPlugin.m @@ -16,7 +16,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if ([@"getIosDeviceInfo" isEqualToString:call.method]) { + if ([@"getDeviceInfo" isEqualToString:call.method]) { UIDevice *device = [UIDevice currentDevice]; struct utsname un; uname(&un); diff --git a/packages/device_info_plus/device_info_plus/macos/Classes/DeviceInfoPlusMacosPlugin.swift b/packages/device_info_plus/device_info_plus/macos/Classes/DeviceInfoPlusMacosPlugin.swift index 61aa8a5d67..e2a0e0c275 100644 --- a/packages/device_info_plus/device_info_plus/macos/Classes/DeviceInfoPlusMacosPlugin.swift +++ b/packages/device_info_plus/device_info_plus/macos/Classes/DeviceInfoPlusMacosPlugin.swift @@ -10,7 +10,7 @@ public class DeviceInfoPlusMacosPlugin: NSObject, FlutterPlugin { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { switch call.method { - case "getMacosDeviceInfo": + case "getDeviceInfo": handleDeviceInfo(result: result) default: result(FlutterMethodNotImplemented) From cc0dc50e9a480434c34110b2d96b6c38d519afba Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:15:30 +0200 Subject: [PATCH 03/13] format --- .../device_info_plus/lib/src/device_info_plus_web.dart | 1 - .../device_info_plus/lib/src/model/ios_device_info.dart | 3 +-- .../device_info_plus/lib/src/model/linux_device_info.dart | 3 --- .../device_info_plus/lib/src/model/macos_device_info.dart | 3 +-- .../device_info_plus/lib/src/model/web_browser_info.dart | 1 - .../device_info_plus/lib/src/model/windows_device_info.dart | 1 - .../lib/method_channel/method_channel_device_info.dart | 4 ++-- 7 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart index d8d0bebb62..65714d885e 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart @@ -45,7 +45,6 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform { } } - extension WebDeviceInfoPlugin on DeviceInfoPlatform { Future webInfo() async { return deviceInfo as WebBrowserInfo; diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart index fd868bc35b..50293875ad 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Information derived from `UIDevice`. @@ -20,7 +19,7 @@ class IosDeviceInfo extends BaseDeviceInfo { this.identifierForVendor, required this.isPhysicalDevice, required this.utsname, - }): super(data); + }) : super(data); /// Device name. final String? name; diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart index 428cc902b8..b83d6c35d0 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/linux_device_info.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Device information for a Linux system. @@ -162,5 +161,3 @@ class LinuxDeviceInfo implements BaseDeviceInfo { }; } } - - diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart index 5a84b55aac..cf7035f996 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/macos_device_info.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// Object encapsulating MACOS device information. @@ -20,7 +19,7 @@ class MacOsDeviceInfo extends BaseDeviceInfo { required this.memorySize, required this.cpuFrequency, required this.systemGUID, - }): super(data); + }) : super(data); /// Name given to the local machine. final String computerName; diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart index b044c914ec..dfad60aa96 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/web_browser_info.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; /// List of supported browsers diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart index d6819beadb..99da4c1fc8 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/windows_device_info.dart @@ -6,7 +6,6 @@ import 'dart:typed_data'; import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; - /// Object encapsulating WINDOWS device information. class WindowsDeviceInfo implements BaseDeviceInfo { /// Constructs a [WindowsDeviceInfo]. diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart index 3b4fea826d..b3343140e8 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart @@ -16,7 +16,7 @@ class MethodChannelDeviceInfo extends DeviceInfoPlatform { // Generic method channel for all devices @override Future deviceInfo() async { - return BaseDeviceInfo((await channel.invokeMethod('getDeviceInfo')) - .cast()); + return BaseDeviceInfo( + (await channel.invokeMethod('getDeviceInfo')).cast()); } } From 56fd3543bc393366bfba494e36c54623b2449761 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:17:20 +0200 Subject: [PATCH 04/13] fix typo --- .../device_info_plus/lib/src/device_info_plus_linux.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart index 819c1a29f6..91f4176f21 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart @@ -29,7 +29,7 @@ class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform { } Future linuxInfo() async { - return deviceInfo as LinuxDeviceInfo; + return (await deviceInfo()) as LinuxDeviceInfo; } Future _getInfo() async { From 2b92a3b9e57ae0ab14819e2132b05599dc62dcbc Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:19:15 +0200 Subject: [PATCH 05/13] remove unused extension --- .../device_info_plus/lib/src/device_info_plus_web.dart | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart index 65714d885e..762c3a29d1 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart @@ -44,9 +44,3 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform { ); } } - -extension WebDeviceInfoPlugin on DeviceInfoPlatform { - Future webInfo() async { - return deviceInfo as WebBrowserInfo; - } -} From 4af607e33f9622d9acbdfb2a9ea149606d8ed065 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:26:43 +0200 Subject: [PATCH 06/13] missing overrides --- .../device_info_plus/lib/src/device_info_plus_web.dart | 2 +- .../device_info_plus/lib/src/device_info_plus_windows.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart index 762c3a29d1..fd3fee6442 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_web.dart @@ -21,7 +21,7 @@ class DeviceInfoPlusWebPlugin extends DeviceInfoPlatform { } @override - Future webBrowserInfo() { + Future deviceInfo() { return Future.value( WebBrowserInfo.fromMap( { diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart index b5cabe1a66..5d037ee3d0 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_windows.dart @@ -25,7 +25,7 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform { /// Returns a [WindowsDeviceInfo] with information about the device. @override - Future windowsInfo() { + Future deviceInfo() { return Future.value(_cache ??= getInfo()); } From 7f10a095fa8c058e7634aa157d1d772d686626de Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:28:56 +0200 Subject: [PATCH 07/13] fix tests --- .../test/device_info_plus_windows_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/test/device_info_plus_windows_test.dart b/packages/device_info_plus/device_info_plus/test/device_info_plus_windows_test.dart index c73b3a14b9..5bf9e3e442 100644 --- a/packages/device_info_plus/device_info_plus/test/device_info_plus_windows_test.dart +++ b/packages/device_info_plus/device_info_plus/test/device_info_plus_windows_test.dart @@ -2,7 +2,7 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; -import 'package:device_info_plus/src/device_info_plus_windows.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:win32/win32.dart'; @@ -113,7 +113,7 @@ void main() { test('windows information', () async { if (Platform.isWindows) { final deviceInfo = DeviceInfoPlusWindowsPlugin(); - final windowsInfo = await deviceInfo.windowsInfo(); + final windowsInfo = (await deviceInfo.deviceInfo()) as WindowsDeviceInfo; // Check whether windowsInfo.numberOfProcessors is an integer. expect(windowsInfo.numberOfCores, isA()); // Check whether windowsInfo.computerName is a valid non-empty string. @@ -187,7 +187,7 @@ void main() { } else { // Expect an exception on non-Windows platforms. final deviceInfo = DeviceInfoPlusWindowsPlugin(); - expect(deviceInfo.windowsInfo, throwsArgumentError); + expect(deviceInfo.deviceInfo, throwsArgumentError); } }); } From b66dec2c7f02987ba333f748c3a6baf75178d151 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 09:30:41 +0200 Subject: [PATCH 08/13] update README --- packages/device_info_plus/device_info_plus/README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/README.md b/packages/device_info_plus/device_info_plus/README.md index 2579bcafed..fc02a48d9c 100644 --- a/packages/device_info_plus/device_info_plus/README.md +++ b/packages/device_info_plus/device_info_plus/README.md @@ -39,22 +39,18 @@ WebBrowserInfo webBrowserInfo = await deviceInfo.webBrowserInfo; print('Running on ${webBrowserInfo.userAgent}'); // e.g. "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0" ``` -The plugin provides a `toMap` method that returns platform-specific device +The plugin provides a `data` method that returns platform-specific device information in a generic way, which can be used for crash-reporting purposes. -However, the data provided by this `toMap` method is currently not serializable +However, the data provided by this `data` method is currently not serializable (i.e. it is not 100% JSON compatible) and shouldn't be treated as such. -That's why the method is currently marked as deprecated and will be eventually -replaced, improved, or removed. We recommend you instead to read the actual -values from each device info platform, or to keep using `toMap` at your own risk. - ```dart import 'package:device_info_plus/device_info_plus.dart'; final deviceInfoPlugin = DeviceInfoPlugin(); final deviceInfo = await deviceInfoPlugin.deviceInfo; -final allInfo = deviceInfo.toMap(); +final allInfo = deviceInfo.data; ``` You will find links to the API docs on the [pub page](https://pub.dev/documentation/device_info_plus/latest/). From 8028498f4cec3e1afb6449e29b789facbd70615d Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 10:06:55 +0200 Subject: [PATCH 09/13] fix deviceInfo method --- .../device_info_plus/lib/device_info_plus.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart index 838de0fb05..87f8d24f70 100644 --- a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart +++ b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart @@ -94,6 +94,22 @@ class DeviceInfoPlugin { /// Returns device information for the current platform. Future get deviceInfo async { + if (kIsWeb) { + return webBrowserInfo; + } else { + if (Platform.isAndroid) { + return androidInfo; + } else if (Platform.isIOS) { + return iosInfo; + } else if (Platform.isLinux) { + return linuxInfo; + } else if (Platform.isMacOS) { + return macOsInfo; + } else if (Platform.isWindows) { + return windowsInfo; + } + } + // allow for extension of the plugin return _platform.deviceInfo(); } } From 688e972dbfb73813bfc8f335da82896c93651a17 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 10:12:38 +0200 Subject: [PATCH 10/13] remove unused --- .../test/method_channel_device_info_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart b/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart index e0a206c939..88bc926d54 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/test/method_channel_device_info_test.dart @@ -6,8 +6,6 @@ import 'package:device_info_plus_platform_interface/method_channel/method_channe import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../../device_info_plus/test/model/android_device_info_fake.dart'; - void main() { TestWidgetsFlutterBinding.ensureInitialized(); From 2c9b4ab210a24b6a70b5decee1550cf8ce82ceaf Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 10:13:08 +0200 Subject: [PATCH 11/13] remove another unused import --- .../device_info_plus/device_info_plus/lib/device_info_plus.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart index 87f8d24f70..f29d486121 100644 --- a/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart +++ b/packages/device_info_plus/device_info_plus/lib/device_info_plus.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:io'; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; -import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:flutter/foundation.dart'; import 'src/model/android_device_info.dart'; From 4432cf1ef25b844e0019728817fdfaf8edfc3e1f Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 11:11:51 +0200 Subject: [PATCH 12/13] lint fixes --- .../lib/src/device_info_plus_linux.dart | 2 -- .../lib/src/model/ios_device_info.dart | 11 ----------- .../method_channel/method_channel_device_info.dart | 1 - 3 files changed, 14 deletions(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart index 91f4176f21..0f7440739d 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart @@ -2,12 +2,10 @@ import 'dart:async'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus_platform_interface/device_info_plus_platform_interface.dart'; -import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:meta/meta.dart'; -import 'model/linux_device_info.dart'; /// See [DeviceInfoPlatform] class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform { diff --git a/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart index 50293875ad..71bf53ab24 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/model/ios_device_info.dart @@ -98,15 +98,4 @@ class IosUtsname { machine: map['machine'], ); } - - /// Serializes [ IosUtsname ] to map. - Map _toMap() { - return { - 'release': release, - 'version': version, - 'machine': machine, - 'sysname': sysname, - 'nodename': nodename, - }; - } } diff --git a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart index b3343140e8..e6cc114ed2 100644 --- a/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart +++ b/packages/device_info_plus/device_info_plus_platform_interface/lib/method_channel/method_channel_device_info.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:device_info_plus_platform_interface/model/base_device_info.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; From baf4625e325391e1abd803c16ce84f164fe6a168 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 26 Oct 2022 11:26:19 +0200 Subject: [PATCH 13/13] formatting --- .../device_info_plus/lib/src/device_info_plus_linux.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart index 0f7440739d..95ab8eaca7 100644 --- a/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart +++ b/packages/device_info_plus/device_info_plus/lib/src/device_info_plus_linux.dart @@ -6,7 +6,6 @@ import 'package:file/file.dart'; import 'package:file/local.dart'; import 'package:meta/meta.dart'; - /// See [DeviceInfoPlatform] class DeviceInfoPlusLinuxPlugin extends DeviceInfoPlatform { /// Register this dart class as the platform implementation for linux