123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- import 'dart:ui';
- import 'package:device_info_plus/device_info_plus.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:package_info_plus/package_info_plus.dart';
- import 'package:plugin_basic/service/config_services_injection.dart';
- import 'package:plugin_platform/engine/sp/sp_util.dart';
- import 'package:shared/utils/device_utils.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:shared/utils/screen_util.dart';
- import '../constants/app_constant.dart';
- class ConfigService extends GetxService {
- static ConfigService get to => Get.find();
-
- RxInt selectCountry = 1.obs;
-
-
- AndroidDeviceInfo? androidDeviceInfo;
-
- IosDeviceInfo? iosDeviceInfo;
-
- Locale locale = PlatformDispatcher.instance.locale;
- PackageInfo? _appPackageInfo;
- String get version => _appPackageInfo?.version ?? '-';
- String get appName => _appPackageInfo?.appName ?? '-';
- String get packageName => _appPackageInfo?.packageName ?? '-';
- String get buildNumber => _appPackageInfo?.buildNumber ?? '-';
- final RxBool _isDarkModel = Get.isDarkMode.obs;
-
- bool get isDarkModel => _isDarkModel.value;
-
- double get safeAreaPaddingTop => _safeAreaPaddingTop!;
-
- double get safeAreaPaddingBottom => _safeAreaPaddingBottom!;
- double? _safeAreaPaddingTop;
- double? _safeAreaPaddingBottom;
-
- Size? mSize;
-
- double? mRatio;
-
- double? width;
- double? height;
-
- double whRatio = 1;
-
- bool isFullScreenDevice = false;
-
- double? topPadding;
- double? bottomPadding;
- double? textScaleFactor;
- Brightness? platformBrightness;
- EdgeInsets? viewInsets;
- EdgeInsets? padding;
- bool? alwaysUse24HourFormat;
- bool? accessibleNavigation;
- bool? invertColors;
- bool? disableAnimations;
- bool? boldText;
- Orientation? orientation;
- @override
- void onInit() {
- super.onInit();
- }
- @override
- void onReady() {
- super.onReady();
-
- int country = SPUtil.getInt(AppConstant.storageSelectedCountry, defValue: 1) ?? 1;
- selectCountry.value = country;
-
- getDeviceInfo();
- getAppInfos();
-
- getMediaInfo(context: Get.context!);
- paddingSizeTop(context: Get.context!);
- paddingSizeBottom(context: Get.context!);
- }
-
- Future<void> getAppInfos() async {
-
- _appPackageInfo = ConfigServicesInjection.packageInfo;
- Log.d('package_info 插件获获取到的app【appName】$appName');
- Log.d('package_info 插件获获取到的app【packageName】$packageName');
- Log.d('package_info 插件获获取到的app【version】$version');
- Log.d('package_info 插件获获取到的app【buildNumber】$buildNumber');
- }
-
- void getDeviceInfo() {
- if (DeviceUtils.isIOS) {
- iosDeviceInfo = ConfigServicesInjection.iosDeviceInfo;
- Log.d('device_info_plus插件获取到设备信息【iosDeviceInfo】$iosDeviceInfo');
- } else if (DeviceUtils.isAndroid) {
- androidDeviceInfo = ConfigServicesInjection.androidDeviceInfo;
- Log.d('device_info_plus插件获取到设备信息【androidDeviceInfo】$androidDeviceInfo');
- }
- }
-
- void initLocale() {}
-
- void onLocaleUpdate(Locale value) {
- locale = value;
- Get.updateLocale(value);
- Log.d('glabalService-app_config_service.dart-更换后的locale【locale】$locale');
- }
-
- Future<void> switchThemeModel() async {
- _isDarkModel.value = !_isDarkModel.value;
-
-
-
- await Future.delayed(const Duration(seconds: 1));
- }
-
- void getMediaInfo({BuildContext? context}) {
-
- mSize = MediaQuery.of(context!).size;
-
- mRatio = MediaQuery.of(context).devicePixelRatio;
-
- width = mSize!.width * mRatio!;
- height = mSize!.height * mRatio!;
- whRatio = (height ?? 1) / (width ?? 1);
- isFullScreenDevice = whRatio > 1.9;
-
- topPadding = MediaQuery.of(context).padding.top;
- bottomPadding = MediaQuery.of(context).padding.bottom;
- textScaleFactor = MediaQuery.of(context).textScaleFactor;
- platformBrightness = MediaQuery.of(context).platformBrightness;
- viewInsets = MediaQuery.of(context).viewInsets;
- padding = MediaQuery.of(context).padding;
- alwaysUse24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
- accessibleNavigation = MediaQuery.of(context).accessibleNavigation;
- invertColors = MediaQuery.of(context).invertColors;
- disableAnimations = MediaQuery.of(context).disableAnimations;
- boldText = MediaQuery.of(context).boldText;
- orientation = MediaQuery.of(context).orientation;
- final screenDensity = MediaQuery.devicePixelRatioOf(context);
-
- setDesignWHD(375, 667, density: screenDensity);
- Log.d('service-app_config_service.dart---设备信息【MediaQuery.of(context)】:${MediaQuery.of(context)}');
- Log.d('service-app_config_service.dart---设备像素比dpr(物理像素/逻辑像素)【mRatio】:$mRatio');
- Log.d('service-app_config_service.dart--- ScreenUtil像素比: $screenDensity');
- Log.d('service-app_config_service.dart---逻辑像素pt【mSize.width * mSize.height】:${mSize!.width} x ${mSize!.height}');
- Log.d('service-app_config_service.dart---屏幕分辨率px(物理像素)【mSize.width * mRatio】 X 【mSize.height * mRatio】:$width x $height '
- '屏幕的宽高比:$whRatio');
- Log.d('service-app_config_service.dart---上边刘海(状态栏)【MediaQuery.of(context).padding.top】:$topPadding');
- Log.d('service-app_config_service.dart---下边导航【MediaQuery.of(context).padding.bottom】:$bottomPadding');
- Log.d('service-app_config_service.dart---textScaleFactor【MediaQuery.of(context).textScaleFactor】: $textScaleFactor');
- Log.d('service-app_config_service.dart---platformBrightness【MediaQuery.of(context).platformBrightness】: $platformBrightness');
- Log.d('service-app_config_service.dart---viewInsets【MediaQuery.of(context).viewInsets】: $viewInsets');
- Log.d('service-app_config_service.dart---padding【MediaQuery.of(context).padding】: $padding');
- Log.d('service-app_config_service.dart---alwaysUse24HourFormat: $alwaysUse24HourFormat');
- Log.d('service-app_config_service.dart---accessibleNavigation: $accessibleNavigation');
- Log.d('service-app_config_service.dart---invertColors: $invertColors');
- Log.d('service-app_config_service.dart---disableAnimations: $disableAnimations');
- Log.d('service-app_config_service.dart---boldText: $boldText');
- Log.d('service-app_config_service.dart---orientation: $orientation');
- }
- double paddingSizeBottom({required BuildContext context}) {
- final MediaQueryData data = MediaQuery.of(context);
- EdgeInsets padding = data.padding;
- padding = padding.copyWith(bottom: data.viewPadding.bottom);
- Log.d("glabalService-config.dart该设备底部的安全距离为----${padding.bottom}");
- _safeAreaPaddingBottom = padding.bottom;
- return padding.bottom;
- }
- double paddingSizeTop({required BuildContext context}) {
- final MediaQueryData data = MediaQuery.of(context);
- EdgeInsets padding = data.padding;
- padding = padding.copyWith(top: data.viewPadding.top);
- Log.d("glabalService-config.dart该设备顶部的安全距离为----${padding.top}");
- _safeAreaPaddingTop = padding.top;
- return padding.top;
- }
- int compareVersionNumbers(String version1, String version2) {
- List<int> v1 = version1.split('.').map(int.parse).toList();
- List<int> v2 = version2.split('.').map(int.parse).toList();
- int minLength = v1.length < v2.length ? v1.length : v2.length;
- for (int i = 0; i < minLength; i++) {
- if (v1[i] < v2[i]) {
- return -1;
- } else if (v1[i] > v2[i]) {
- return 1;
- }
- }
- if (v1.length < v2.length) {
- return -1;
- } else if (v1.length > v2.length) {
- return 1;
- }
- return 0;
- }
- }
|