55 lines
1.4 KiB
Dart
55 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DeviceUtils {
|
|
DeviceUtils._();
|
|
|
|
static double screenWidth(BuildContext context) =>
|
|
MediaQuery.sizeOf(context).width;
|
|
|
|
static double screenHeight(BuildContext context) =>
|
|
MediaQuery.sizeOf(context).height;
|
|
|
|
static double topSafePadding(BuildContext context) =>
|
|
MediaQuery.paddingOf(context).top;
|
|
|
|
static double bottomSafePadding(BuildContext context) =>
|
|
MediaQuery.paddingOf(context).bottom;
|
|
|
|
static Future<bool> isPhysicalDevice() async {
|
|
final plugin = DeviceInfoPlugin();
|
|
if (Platform.isAndroid) {
|
|
return (await plugin.androidInfo).isPhysicalDevice;
|
|
}
|
|
if (Platform.isIOS) {
|
|
return (await plugin.iosInfo).isPhysicalDevice;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static Future<Map<String, String>> deviceInfo() async {
|
|
final plugin = DeviceInfoPlugin();
|
|
if (Platform.isAndroid) {
|
|
final info = await plugin.androidInfo;
|
|
return {
|
|
'platform': 'android',
|
|
'brand': info.brand,
|
|
'model': info.model,
|
|
'systemVersion': info.version.release,
|
|
};
|
|
}
|
|
if (Platform.isIOS) {
|
|
final info = await plugin.iosInfo;
|
|
return {
|
|
'platform': 'ios',
|
|
'brand': info.systemName,
|
|
'model': info.utsname.machine,
|
|
'systemVersion': info.systemVersion,
|
|
};
|
|
}
|
|
return {'platform': Platform.operatingSystem};
|
|
}
|
|
}
|