app_config.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // 应用相关操作状态 State 类,用于 RiverPod 中 Provider 的定义
  2. import 'package:device_info_plus/device_info_plus.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:package_info_plus/package_info_plus.dart';
  5. import 'package:shared/utils/device_utils.dart';
  6. class AppConfig {
  7. /// android 设备信息
  8. AndroidDeviceInfo? androidDeviceInfo;
  9. /// ios 设备信息
  10. IosDeviceInfo? iosDeviceInfo;
  11. /// 包信息
  12. PackageInfo? packageInfo;
  13. double? _safeAreaPaddingTop;
  14. double? _safeAreaPaddingBottom;
  15. //屏幕大小
  16. Size? mSize;
  17. //密度
  18. double? mRatio;
  19. //设备像素px
  20. double? width;
  21. double? height;
  22. //设备宽高比,大于1.9是全面屏手机
  23. double whRatio = 1;
  24. double density = 0;
  25. //是否是全面屏设备(宽高比大于1.9)
  26. bool isFullScreenDevice = false;
  27. // 上下边距 (主要用于 刘海 和 内置导航键)
  28. double? topPadding;
  29. double? bottomPadding;
  30. double? textScaleFactor;
  31. Brightness? platformBrightness;
  32. EdgeInsets? viewInsets;
  33. EdgeInsets? padding;
  34. bool? alwaysUse24HourFormat;
  35. bool? accessibleNavigation;
  36. bool? invertColors;
  37. bool? disableAnimations;
  38. bool? boldText;
  39. Orientation? orientation;
  40. /// 是否 release 包(生产环境)
  41. bool get isRelease => const bool.fromEnvironment("dart.vm.product");
  42. String get version => packageInfo?.version ?? '-';
  43. String get appName => packageInfo?.appName ?? '-';
  44. String get packageName => packageInfo?.packageName ?? '-';
  45. String get buildNumber => packageInfo?.buildNumber ?? '-';
  46. // 顶部安全距离(pt)
  47. double get safeAreaPaddingTop => _safeAreaPaddingTop!;
  48. // 底部安全距离(pt)
  49. double get safeAreaPaddingBottom => _safeAreaPaddingBottom!;
  50. // 获取当前Android设备的Android版本
  51. int getAndroidSdkInt() {
  52. if (DeviceUtils.isAndroid) {
  53. return androidDeviceInfo?.version.sdkInt ?? -1;
  54. } else {
  55. return -1;
  56. }
  57. }
  58. //===================== 插件自动生成-无需手动修改 ↓ ===================================
  59. //<editor-fold desc="Data Methods">
  60. AppConfig({
  61. this.androidDeviceInfo,
  62. this.iosDeviceInfo,
  63. this.packageInfo,
  64. this.mSize,
  65. this.mRatio,
  66. this.width,
  67. this.height,
  68. required this.whRatio,
  69. required this.density,
  70. required this.isFullScreenDevice,
  71. this.topPadding,
  72. this.bottomPadding,
  73. this.textScaleFactor,
  74. this.platformBrightness,
  75. this.viewInsets,
  76. this.padding,
  77. this.alwaysUse24HourFormat,
  78. this.accessibleNavigation,
  79. this.invertColors,
  80. this.disableAnimations,
  81. this.boldText,
  82. this.orientation,
  83. required double? safeAreaPaddingTop,
  84. required double? safeAreaPaddingBottom,
  85. }) : _safeAreaPaddingTop = safeAreaPaddingTop,
  86. _safeAreaPaddingBottom = safeAreaPaddingBottom;
  87. @override
  88. bool operator ==(Object other) =>
  89. identical(this, other) ||
  90. (other is AppConfig &&
  91. runtimeType == other.runtimeType &&
  92. androidDeviceInfo == other.androidDeviceInfo &&
  93. iosDeviceInfo == other.iosDeviceInfo &&
  94. packageInfo == other.packageInfo &&
  95. _safeAreaPaddingTop == other._safeAreaPaddingTop &&
  96. _safeAreaPaddingBottom == other._safeAreaPaddingBottom &&
  97. mSize == other.mSize &&
  98. mRatio == other.mRatio &&
  99. width == other.width &&
  100. height == other.height &&
  101. whRatio == other.whRatio &&
  102. density == other.density &&
  103. isFullScreenDevice == other.isFullScreenDevice &&
  104. topPadding == other.topPadding &&
  105. bottomPadding == other.bottomPadding &&
  106. textScaleFactor == other.textScaleFactor &&
  107. platformBrightness == other.platformBrightness &&
  108. viewInsets == other.viewInsets &&
  109. padding == other.padding &&
  110. alwaysUse24HourFormat == other.alwaysUse24HourFormat &&
  111. accessibleNavigation == other.accessibleNavigation &&
  112. invertColors == other.invertColors &&
  113. disableAnimations == other.disableAnimations &&
  114. boldText == other.boldText &&
  115. orientation == other.orientation);
  116. @override
  117. int get hashCode =>
  118. androidDeviceInfo.hashCode ^
  119. iosDeviceInfo.hashCode ^
  120. packageInfo.hashCode ^
  121. _safeAreaPaddingTop.hashCode ^
  122. _safeAreaPaddingBottom.hashCode ^
  123. mSize.hashCode ^
  124. mRatio.hashCode ^
  125. width.hashCode ^
  126. height.hashCode ^
  127. whRatio.hashCode ^
  128. density.hashCode ^
  129. isFullScreenDevice.hashCode ^
  130. topPadding.hashCode ^
  131. bottomPadding.hashCode ^
  132. textScaleFactor.hashCode ^
  133. platformBrightness.hashCode ^
  134. viewInsets.hashCode ^
  135. padding.hashCode ^
  136. alwaysUse24HourFormat.hashCode ^
  137. accessibleNavigation.hashCode ^
  138. invertColors.hashCode ^
  139. disableAnimations.hashCode ^
  140. boldText.hashCode ^
  141. orientation.hashCode;
  142. @override
  143. String toString() {
  144. return 'AppConfig{' +
  145. ' androidDeviceInfo: $androidDeviceInfo,' +
  146. ' iosDeviceInfo: $iosDeviceInfo,' +
  147. ' packageInfo: $packageInfo,' +
  148. ' _safeAreaPaddingTop: $_safeAreaPaddingTop,' +
  149. ' _safeAreaPaddingBottom: $_safeAreaPaddingBottom,' +
  150. ' mSize: $mSize,' +
  151. ' mRatio: $mRatio,' +
  152. ' width: $width,' +
  153. ' height: $height,' +
  154. ' whRatio: $whRatio,' +
  155. ' density: $density,' +
  156. ' isFullScreenDevice: $isFullScreenDevice,' +
  157. ' topPadding: $topPadding,' +
  158. ' bottomPadding: $bottomPadding,' +
  159. ' textScaleFactor: $textScaleFactor,' +
  160. ' platformBrightness: $platformBrightness,' +
  161. ' viewInsets: $viewInsets,' +
  162. ' padding: $padding,' +
  163. ' alwaysUse24HourFormat: $alwaysUse24HourFormat,' +
  164. ' accessibleNavigation: $accessibleNavigation,' +
  165. ' invertColors: $invertColors,' +
  166. ' disableAnimations: $disableAnimations,' +
  167. ' boldText: $boldText,' +
  168. ' orientation: $orientation,' +
  169. '}';
  170. }
  171. AppConfig copyWith({
  172. AndroidDeviceInfo? androidDeviceInfo,
  173. IosDeviceInfo? iosDeviceInfo,
  174. PackageInfo? packageInfo,
  175. double? safeAreaPaddingTop,
  176. double? safeAreaPaddingBottom,
  177. Size? mSize,
  178. double? mRatio,
  179. double? width,
  180. double? height,
  181. double? whRatio,
  182. double? density,
  183. bool? isFullScreenDevice,
  184. double? topPadding,
  185. double? bottomPadding,
  186. double? textScaleFactor,
  187. Brightness? platformBrightness,
  188. EdgeInsets? viewInsets,
  189. EdgeInsets? padding,
  190. bool? alwaysUse24HourFormat,
  191. bool? accessibleNavigation,
  192. bool? invertColors,
  193. bool? disableAnimations,
  194. bool? boldText,
  195. Orientation? orientation,
  196. }) {
  197. return AppConfig(
  198. androidDeviceInfo: androidDeviceInfo ?? this.androidDeviceInfo,
  199. iosDeviceInfo: iosDeviceInfo ?? this.iosDeviceInfo,
  200. packageInfo: packageInfo ?? this.packageInfo,
  201. safeAreaPaddingTop: safeAreaPaddingTop ?? this._safeAreaPaddingTop,
  202. safeAreaPaddingBottom: safeAreaPaddingBottom ?? this._safeAreaPaddingBottom,
  203. mSize: mSize ?? this.mSize,
  204. mRatio: mRatio ?? this.mRatio,
  205. width: width ?? this.width,
  206. height: height ?? this.height,
  207. whRatio: whRatio ?? this.whRatio,
  208. density: density ?? this.density,
  209. isFullScreenDevice: isFullScreenDevice ?? this.isFullScreenDevice,
  210. topPadding: topPadding ?? this.topPadding,
  211. bottomPadding: bottomPadding ?? this.bottomPadding,
  212. textScaleFactor: textScaleFactor ?? this.textScaleFactor,
  213. platformBrightness: platformBrightness ?? this.platformBrightness,
  214. viewInsets: viewInsets ?? this.viewInsets,
  215. padding: padding ?? this.padding,
  216. alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat,
  217. accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation,
  218. invertColors: invertColors ?? this.invertColors,
  219. disableAnimations: disableAnimations ?? this.disableAnimations,
  220. boldText: boldText ?? this.boldText,
  221. orientation: orientation ?? this.orientation,
  222. );
  223. }
  224. //</editor-fold>
  225. }