From 348e0fea637cc3d7d4d35d488d46e47cb543e65d Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Wed, 28 Jun 2023 12:42:13 +0300 Subject: [PATCH] [flutter_example_packages] Fix registerWith --- .../lib/packages/device_info_plus/model.dart | 244 +++++++++++++++++- .../lib/packages/device_info_plus/page.dart | 87 ++++++- .../lib/battery_plus_aurora.dart | 4 + .../lib/device_info_plus_aurora.dart | 4 + 4 files changed, 336 insertions(+), 3 deletions(-) diff --git a/example/lib/packages/device_info_plus/model.dart b/example/lib/packages/device_info_plus/model.dart index 113f117..20c40c8 100644 --- a/example/lib/packages/device_info_plus/model.dart +++ b/example/lib/packages/device_info_plus/model.dart @@ -1,10 +1,19 @@ +import 'package:device_info_plus/device_info_plus.dart'; +import 'package:device_info_plus_aurora/aurora_device_info.dart'; import 'package:flutter/widgets.dart'; import 'package:scoped_model/scoped_model.dart'; /// Model for [DeviceInfoPlusPage] class DeviceInfoPlusModel extends Model { /// Get [ScopedModel] - static DeviceInfoPlusModel of(BuildContext context) => ScopedModel.of(context); + static DeviceInfoPlusModel of(BuildContext context) => + ScopedModel.of(context); + + final _deviceInfoPlugin = DeviceInfoPlugin(); + + /// Get Aurora info + Future get _deviceInfo async => + await _deviceInfoPlugin.linuxInfo as AuroraDeviceInfo; /// Error String? _error; @@ -14,4 +23,235 @@ class DeviceInfoPlusModel extends Model { /// Public is error bool get isError => _error != null; -} \ No newline at end of file + + /// Get ID name device + Future getID() async { + try { + return (await _deviceInfo).id; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Device name + Future getName() async { + try { + return (await _deviceInfo).name; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Version + Future getVersion() async { + try { + return (await _deviceInfo).version; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Device full name + Future getPrettyName() async { + try { + return (await _deviceInfo).prettyName; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Check has GNSS + Future hasGNSS() async { + try { + return (await _deviceInfo).hasGNSS; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Check has NFC + Future hasNFC() async { + try { + return (await _deviceInfo).hasNFC; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Check has Bluetooth + Future hasBluetooth() async { + try { + return (await _deviceInfo).hasBluetooth; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Check has Wlan + Future hasWlan() async { + try { + return (await _deviceInfo).hasWlan; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Max CPU clock speed + Future getMaxCpuClockSpeed() async { + try { + return (await _deviceInfo).maxCpuClockSpeed; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Number CPU cores + Future getNumberCpuCores() async { + try { + return (await _deviceInfo).numberCpuCores; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Get battery level in percent 0-100 + Future getBatteryChargePercentage() async { + try { + return (await _deviceInfo).batteryChargePercentage; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Camera resolution + Future getMainCameraResolution() async { + try { + return (await _deviceInfo).mainCameraResolution; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Frontal camera resolution + Future getFrontalCameraResolution() async { + try { + return (await _deviceInfo).frontalCameraResolution; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// RAM total size + Future getRamTotalSize() async { + try { + return (await _deviceInfo).ramTotalSize; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// RAM free size + Future getRamFreeSize() async { + try { + return (await _deviceInfo).ramFreeSize; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Screen resolution + Future getScreenResolution() async { + try { + return (await _deviceInfo).screenResolution; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Version @todo + Future getOsVersion() async { + try { + return (await _deviceInfo).osVersion; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Device model + Future getDeviceModel() async { + try { + return (await _deviceInfo).deviceModel; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Get map with info about external storage + Future?> getExternalStorage() async { + try { + return (await _deviceInfo).externalStorage; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Get map with info about internal storage + Future?> getInternalStorage() async { + try { + return (await _deviceInfo).internalStorage; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } + + /// Get map with info about SIM cards + Future>?> getSimCards() async { + try { + return (await _deviceInfo).simCards; + } catch (e) { + _error = e.toString(); + } + notifyListeners(); + return null; + } +} diff --git a/example/lib/packages/device_info_plus/page.dart b/example/lib/packages/device_info_plus/page.dart index e10b726..96b691f 100644 --- a/example/lib/packages/device_info_plus/page.dart +++ b/example/lib/packages/device_info_plus/page.dart @@ -45,7 +45,92 @@ class _DeviceInfoPlusPageState extends AppState { BlockItem( title: l10n.deviceInfoPlusTitle, desc: l10n.deviceInfoPlusDesc, - value: null, + future: model.getID(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getName(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getVersion(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getPrettyName(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.hasGNSS(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.hasNFC(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.hasBluetooth(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.hasWlan(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getMaxCpuClockSpeed(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getNumberCpuCores(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getBatteryChargePercentage(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getMainCameraResolution(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getFrontalCameraResolution(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getRamTotalSize(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getRamFreeSize(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getScreenResolution(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getOsVersion(), + ), + BlockItem( + title: l10n.deviceInfoPlusTitle, + desc: l10n.deviceInfoPlusDesc, + future: model.getDeviceModel(), ), ], ), diff --git a/packages/battery_plus/battery_plus_aurora/lib/battery_plus_aurora.dart b/packages/battery_plus/battery_plus_aurora/lib/battery_plus_aurora.dart index 94040d0..9d741fb 100644 --- a/packages/battery_plus/battery_plus_aurora/lib/battery_plus_aurora.dart +++ b/packages/battery_plus/battery_plus_aurora/lib/battery_plus_aurora.dart @@ -13,6 +13,10 @@ import 'package:async/async.dart' show StreamGroup; class BatteryPlusAurora extends BatteryPlatform { /// Register this dart class as the platform implementation for aurora static void registerWith() { + + debugPrint("BatteryPlusAurora"); + debugPrint(defaultTargetPlatform.toString()); + if (TargetPlatform.aurora == defaultTargetPlatform) { BatteryPlatform.instance = BatteryPlusAurora(); } diff --git a/packages/device_info_plus/device_info_plus_aurora/lib/device_info_plus_aurora.dart b/packages/device_info_plus/device_info_plus_aurora/lib/device_info_plus_aurora.dart index df96320..4392aba 100644 --- a/packages/device_info_plus/device_info_plus_aurora/lib/device_info_plus_aurora.dart +++ b/packages/device_info_plus/device_info_plus_aurora/lib/device_info_plus_aurora.dart @@ -14,6 +14,10 @@ import 'aurora_device_info.dart'; class DeviceInfoPlusAurora extends DeviceInfoPlatform { /// Register this dart class as the platform implementation for aurora static void registerWith() { + + debugPrint("DeviceInfoPlusAurora"); + debugPrint(defaultTargetPlatform.toString()); + if (TargetPlatform.aurora == defaultTargetPlatform) { DeviceInfoPlatform.instance = DeviceInfoPlusAurora(); } else {