Browse Source

[flutter_example_packages] Fix registerWith

merge-requests/21/head
Vitaliy Zarubin 2 years ago
parent
commit
348e0fea63
  1. 244
      example/lib/packages/device_info_plus/model.dart
  2. 87
      example/lib/packages/device_info_plus/page.dart
  3. 4
      packages/battery_plus/battery_plus_aurora/lib/battery_plus_aurora.dart
  4. 4
      packages/device_info_plus/device_info_plus_aurora/lib/device_info_plus_aurora.dart

244
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<DeviceInfoPlusModel>(context);
static DeviceInfoPlusModel of(BuildContext context) =>
ScopedModel.of<DeviceInfoPlusModel>(context);
final _deviceInfoPlugin = DeviceInfoPlugin();
/// Get Aurora info
Future<AuroraDeviceInfo> 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;
}
/// Get ID name device
Future<String?> getID() async {
try {
return (await _deviceInfo).id;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Device name
Future<String?> getName() async {
try {
return (await _deviceInfo).name;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Version
Future<String?> getVersion() async {
try {
return (await _deviceInfo).version;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Device full name
Future<String?> getPrettyName() async {
try {
return (await _deviceInfo).prettyName;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Check has GNSS
Future<bool?> hasGNSS() async {
try {
return (await _deviceInfo).hasGNSS;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Check has NFC
Future<bool?> hasNFC() async {
try {
return (await _deviceInfo).hasNFC;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Check has Bluetooth
Future<bool?> hasBluetooth() async {
try {
return (await _deviceInfo).hasBluetooth;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Check has Wlan
Future<bool?> hasWlan() async {
try {
return (await _deviceInfo).hasWlan;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Max CPU clock speed
Future<int?> getMaxCpuClockSpeed() async {
try {
return (await _deviceInfo).maxCpuClockSpeed;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Number CPU cores
Future<int?> getNumberCpuCores() async {
try {
return (await _deviceInfo).numberCpuCores;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Get battery level in percent 0-100
Future<int?> getBatteryChargePercentage() async {
try {
return (await _deviceInfo).batteryChargePercentage;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Camera resolution
Future<double?> getMainCameraResolution() async {
try {
return (await _deviceInfo).mainCameraResolution;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Frontal camera resolution
Future<double?> getFrontalCameraResolution() async {
try {
return (await _deviceInfo).frontalCameraResolution;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// RAM total size
Future<int?> getRamTotalSize() async {
try {
return (await _deviceInfo).ramTotalSize;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// RAM free size
Future<int?> getRamFreeSize() async {
try {
return (await _deviceInfo).ramFreeSize;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Screen resolution
Future<String?> getScreenResolution() async {
try {
return (await _deviceInfo).screenResolution;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Version @todo
Future<String?> getOsVersion() async {
try {
return (await _deviceInfo).osVersion;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Device model
Future<String?> getDeviceModel() async {
try {
return (await _deviceInfo).deviceModel;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Get map with info about external storage
Future<Map<String, dynamic>?> getExternalStorage() async {
try {
return (await _deviceInfo).externalStorage;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Get map with info about internal storage
Future<Map<String, dynamic>?> getInternalStorage() async {
try {
return (await _deviceInfo).internalStorage;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
/// Get map with info about SIM cards
Future<List<Map<String, dynamic>>?> getSimCards() async {
try {
return (await _deviceInfo).simCards;
} catch (e) {
_error = e.toString();
}
notifyListeners();
return null;
}
}

87
example/lib/packages/device_info_plus/page.dart

@ -45,7 +45,92 @@ class _DeviceInfoPlusPageState extends AppState<DeviceInfoPlusPage> {
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(),
),
],
),

4
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();
}

4
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 {

Loading…
Cancel
Save