|
@@ -0,0 +1,253 @@
|
|
|
+// 应用相关操作状态 State 类,用于 RiverPod 中 Provider 的定义
|
|
|
+import 'package:device_info_plus/device_info_plus.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:package_info_plus/package_info_plus.dart';
|
|
|
+import 'package:shared/utils/device_utils.dart';
|
|
|
+
|
|
|
+class AppConfig {
|
|
|
+ /// android 设备信息
|
|
|
+ AndroidDeviceInfo? androidDeviceInfo;
|
|
|
+
|
|
|
+ /// ios 设备信息
|
|
|
+ IosDeviceInfo? iosDeviceInfo;
|
|
|
+
|
|
|
+ /// 包信息
|
|
|
+ PackageInfo? packageInfo;
|
|
|
+
|
|
|
+ double? _safeAreaPaddingTop;
|
|
|
+
|
|
|
+ double? _safeAreaPaddingBottom;
|
|
|
+
|
|
|
+ //屏幕大小
|
|
|
+ Size? mSize;
|
|
|
+
|
|
|
+ //密度
|
|
|
+ double? mRatio;
|
|
|
+
|
|
|
+ //设备像素px
|
|
|
+ double? width;
|
|
|
+ double? height;
|
|
|
+
|
|
|
+ //设备宽高比,大于1.9是全面屏手机
|
|
|
+ double whRatio = 1;
|
|
|
+ double density = 0;
|
|
|
+
|
|
|
+ //是否是全面屏设备(宽高比大于1.9)
|
|
|
+ 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;
|
|
|
+
|
|
|
+ /// 是否 release 包(生产环境)
|
|
|
+ bool get isRelease => const bool.fromEnvironment("dart.vm.product");
|
|
|
+
|
|
|
+ String get version => packageInfo?.version ?? '-';
|
|
|
+
|
|
|
+ String get appName => packageInfo?.appName ?? '-';
|
|
|
+
|
|
|
+ String get packageName => packageInfo?.packageName ?? '-';
|
|
|
+
|
|
|
+ String get buildNumber => packageInfo?.buildNumber ?? '-';
|
|
|
+
|
|
|
+ // 顶部安全距离(pt)
|
|
|
+ double get safeAreaPaddingTop => _safeAreaPaddingTop!;
|
|
|
+
|
|
|
+ // 底部安全距离(pt)
|
|
|
+ double get safeAreaPaddingBottom => _safeAreaPaddingBottom!;
|
|
|
+
|
|
|
+ // 获取当前Android设备的Android版本
|
|
|
+ int getAndroidSdkInt() {
|
|
|
+ if (DeviceUtils.isAndroid) {
|
|
|
+ return androidDeviceInfo?.version.sdkInt ?? -1;
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //===================== 插件自动生成-无需手动修改 ↓ ===================================
|
|
|
+
|
|
|
+//<editor-fold desc="Data Methods">
|
|
|
+
|
|
|
+ AppConfig({
|
|
|
+ this.androidDeviceInfo,
|
|
|
+ this.iosDeviceInfo,
|
|
|
+ this.packageInfo,
|
|
|
+ this.mSize,
|
|
|
+ this.mRatio,
|
|
|
+ this.width,
|
|
|
+ this.height,
|
|
|
+ required this.whRatio,
|
|
|
+ required this.density,
|
|
|
+ required this.isFullScreenDevice,
|
|
|
+ this.topPadding,
|
|
|
+ this.bottomPadding,
|
|
|
+ this.textScaleFactor,
|
|
|
+ this.platformBrightness,
|
|
|
+ this.viewInsets,
|
|
|
+ this.padding,
|
|
|
+ this.alwaysUse24HourFormat,
|
|
|
+ this.accessibleNavigation,
|
|
|
+ this.invertColors,
|
|
|
+ this.disableAnimations,
|
|
|
+ this.boldText,
|
|
|
+ this.orientation,
|
|
|
+ required double? safeAreaPaddingTop,
|
|
|
+ required double? safeAreaPaddingBottom,
|
|
|
+ }) : _safeAreaPaddingTop = safeAreaPaddingTop,
|
|
|
+ _safeAreaPaddingBottom = safeAreaPaddingBottom;
|
|
|
+
|
|
|
+ @override
|
|
|
+ bool operator ==(Object other) =>
|
|
|
+ identical(this, other) ||
|
|
|
+ (other is AppConfig &&
|
|
|
+ runtimeType == other.runtimeType &&
|
|
|
+ androidDeviceInfo == other.androidDeviceInfo &&
|
|
|
+ iosDeviceInfo == other.iosDeviceInfo &&
|
|
|
+ packageInfo == other.packageInfo &&
|
|
|
+ _safeAreaPaddingTop == other._safeAreaPaddingTop &&
|
|
|
+ _safeAreaPaddingBottom == other._safeAreaPaddingBottom &&
|
|
|
+ mSize == other.mSize &&
|
|
|
+ mRatio == other.mRatio &&
|
|
|
+ width == other.width &&
|
|
|
+ height == other.height &&
|
|
|
+ whRatio == other.whRatio &&
|
|
|
+ density == other.density &&
|
|
|
+ isFullScreenDevice == other.isFullScreenDevice &&
|
|
|
+ topPadding == other.topPadding &&
|
|
|
+ bottomPadding == other.bottomPadding &&
|
|
|
+ textScaleFactor == other.textScaleFactor &&
|
|
|
+ platformBrightness == other.platformBrightness &&
|
|
|
+ viewInsets == other.viewInsets &&
|
|
|
+ padding == other.padding &&
|
|
|
+ alwaysUse24HourFormat == other.alwaysUse24HourFormat &&
|
|
|
+ accessibleNavigation == other.accessibleNavigation &&
|
|
|
+ invertColors == other.invertColors &&
|
|
|
+ disableAnimations == other.disableAnimations &&
|
|
|
+ boldText == other.boldText &&
|
|
|
+ orientation == other.orientation);
|
|
|
+
|
|
|
+ @override
|
|
|
+ int get hashCode =>
|
|
|
+ androidDeviceInfo.hashCode ^
|
|
|
+ iosDeviceInfo.hashCode ^
|
|
|
+ packageInfo.hashCode ^
|
|
|
+ _safeAreaPaddingTop.hashCode ^
|
|
|
+ _safeAreaPaddingBottom.hashCode ^
|
|
|
+ mSize.hashCode ^
|
|
|
+ mRatio.hashCode ^
|
|
|
+ width.hashCode ^
|
|
|
+ height.hashCode ^
|
|
|
+ whRatio.hashCode ^
|
|
|
+ density.hashCode ^
|
|
|
+ isFullScreenDevice.hashCode ^
|
|
|
+ topPadding.hashCode ^
|
|
|
+ bottomPadding.hashCode ^
|
|
|
+ textScaleFactor.hashCode ^
|
|
|
+ platformBrightness.hashCode ^
|
|
|
+ viewInsets.hashCode ^
|
|
|
+ padding.hashCode ^
|
|
|
+ alwaysUse24HourFormat.hashCode ^
|
|
|
+ accessibleNavigation.hashCode ^
|
|
|
+ invertColors.hashCode ^
|
|
|
+ disableAnimations.hashCode ^
|
|
|
+ boldText.hashCode ^
|
|
|
+ orientation.hashCode;
|
|
|
+
|
|
|
+ @override
|
|
|
+ String toString() {
|
|
|
+ return 'AppConfig{' +
|
|
|
+ ' androidDeviceInfo: $androidDeviceInfo,' +
|
|
|
+ ' iosDeviceInfo: $iosDeviceInfo,' +
|
|
|
+ ' packageInfo: $packageInfo,' +
|
|
|
+ ' _safeAreaPaddingTop: $_safeAreaPaddingTop,' +
|
|
|
+ ' _safeAreaPaddingBottom: $_safeAreaPaddingBottom,' +
|
|
|
+ ' mSize: $mSize,' +
|
|
|
+ ' mRatio: $mRatio,' +
|
|
|
+ ' width: $width,' +
|
|
|
+ ' height: $height,' +
|
|
|
+ ' whRatio: $whRatio,' +
|
|
|
+ ' density: $density,' +
|
|
|
+ ' isFullScreenDevice: $isFullScreenDevice,' +
|
|
|
+ ' topPadding: $topPadding,' +
|
|
|
+ ' bottomPadding: $bottomPadding,' +
|
|
|
+ ' textScaleFactor: $textScaleFactor,' +
|
|
|
+ ' platformBrightness: $platformBrightness,' +
|
|
|
+ ' viewInsets: $viewInsets,' +
|
|
|
+ ' padding: $padding,' +
|
|
|
+ ' alwaysUse24HourFormat: $alwaysUse24HourFormat,' +
|
|
|
+ ' accessibleNavigation: $accessibleNavigation,' +
|
|
|
+ ' invertColors: $invertColors,' +
|
|
|
+ ' disableAnimations: $disableAnimations,' +
|
|
|
+ ' boldText: $boldText,' +
|
|
|
+ ' orientation: $orientation,' +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+
|
|
|
+ AppConfig copyWith({
|
|
|
+ AndroidDeviceInfo? androidDeviceInfo,
|
|
|
+ IosDeviceInfo? iosDeviceInfo,
|
|
|
+ PackageInfo? packageInfo,
|
|
|
+ double? safeAreaPaddingTop,
|
|
|
+ double? safeAreaPaddingBottom,
|
|
|
+ Size? mSize,
|
|
|
+ double? mRatio,
|
|
|
+ double? width,
|
|
|
+ double? height,
|
|
|
+ double? whRatio,
|
|
|
+ double? density,
|
|
|
+ bool? isFullScreenDevice,
|
|
|
+ double? topPadding,
|
|
|
+ double? bottomPadding,
|
|
|
+ double? textScaleFactor,
|
|
|
+ Brightness? platformBrightness,
|
|
|
+ EdgeInsets? viewInsets,
|
|
|
+ EdgeInsets? padding,
|
|
|
+ bool? alwaysUse24HourFormat,
|
|
|
+ bool? accessibleNavigation,
|
|
|
+ bool? invertColors,
|
|
|
+ bool? disableAnimations,
|
|
|
+ bool? boldText,
|
|
|
+ Orientation? orientation,
|
|
|
+ }) {
|
|
|
+ return AppConfig(
|
|
|
+ androidDeviceInfo: androidDeviceInfo ?? this.androidDeviceInfo,
|
|
|
+ iosDeviceInfo: iosDeviceInfo ?? this.iosDeviceInfo,
|
|
|
+ packageInfo: packageInfo ?? this.packageInfo,
|
|
|
+ safeAreaPaddingTop: safeAreaPaddingTop ?? this._safeAreaPaddingTop,
|
|
|
+ safeAreaPaddingBottom: safeAreaPaddingBottom ?? this._safeAreaPaddingBottom,
|
|
|
+ mSize: mSize ?? this.mSize,
|
|
|
+ mRatio: mRatio ?? this.mRatio,
|
|
|
+ width: width ?? this.width,
|
|
|
+ height: height ?? this.height,
|
|
|
+ whRatio: whRatio ?? this.whRatio,
|
|
|
+ density: density ?? this.density,
|
|
|
+ isFullScreenDevice: isFullScreenDevice ?? this.isFullScreenDevice,
|
|
|
+ topPadding: topPadding ?? this.topPadding,
|
|
|
+ bottomPadding: bottomPadding ?? this.bottomPadding,
|
|
|
+ textScaleFactor: textScaleFactor ?? this.textScaleFactor,
|
|
|
+ platformBrightness: platformBrightness ?? this.platformBrightness,
|
|
|
+ viewInsets: viewInsets ?? this.viewInsets,
|
|
|
+ padding: padding ?? this.padding,
|
|
|
+ alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat,
|
|
|
+ accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation,
|
|
|
+ invertColors: invertColors ?? this.invertColors,
|
|
|
+ disableAnimations: disableAnimations ?? this.disableAnimations,
|
|
|
+ boldText: boldText ?? this.boldText,
|
|
|
+ orientation: orientation ?? this.orientation,
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+//</editor-fold>
|
|
|
+}
|