app.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  5. import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
  6. import '../config/theme/ix_theme.dart';
  7. import '../config/translations/localization_service.dart';
  8. import '../config/translations/strings_enum.dart';
  9. import '../utils/developer/ix_developer_tools.dart';
  10. import '../utils/device_manager.dart';
  11. import '../utils/ix_back_button_dispatcher.dart';
  12. import '../utils/log/logger.dart';
  13. import 'components/ix_snackbar.dart';
  14. import 'constants/configs.dart';
  15. import 'data/sp/ix_sp.dart';
  16. import 'routes/app_pages.dart';
  17. import 'package:flutter_screenutil/flutter_screenutil.dart';
  18. import 'widgets/click_opacity.dart';
  19. import 'widgets/gradient_circle_header.dart';
  20. import 'widgets/triple_tap_detector.dart';
  21. class App extends StatelessWidget {
  22. const App({super.key});
  23. @override
  24. Widget build(BuildContext context) {
  25. return ScreenUtilInit(
  26. designSize: const Size(375, 812),
  27. minTextAdapt: true,
  28. splitScreenMode: true,
  29. useInheritedMediaQuery: true,
  30. rebuildFactor: (old, data) => true,
  31. builder: (context, widget) => RefreshConfiguration(
  32. headerBuilder: () =>
  33. GradientCircleHeader(), // 配置默认页眉指示器。如果您每个页面都有相同的页眉指示器,您需要设置此
  34. footerBuilder: () => ClassicFooter(), // 配置默认底部指示器
  35. headerTriggerDistance: 80.0, // 标题触发刷新触发距离
  36. springDescription: SpringDescription(
  37. mass: 1,
  38. stiffness: 1000,
  39. damping: 100,
  40. ), // 自定义弹簧回弹动画,属性含义请参阅Flutter API
  41. maxOverScrollExtent: 40, //头部最大拖动范围。如果发生超出视图区域的情况,请设置此属性
  42. maxUnderScrollExtent: 0, // 底部最大拖动范围
  43. enableScrollWhenRefreshCompleted:
  44. true, //此属性与PageView和TabBarView不兼容。如果您需要TabBarView左右滑动,则需要将其设置为true。
  45. enableLoadingWhenFailed: true, //在负载失败的情况下,用户仍然可以通过手势下拉触发更多负载。
  46. hideFooterWhenNotFull: false, //禁用上拉加载更多功能,当视口小于一屏时
  47. enableBallisticLoad: true, //触发通过BallisticScrollActivity加载更多
  48. child: _buildMaterialApp(),
  49. ),
  50. );
  51. }
  52. Widget _buildMaterialApp() {
  53. bool isLightTheme = IXSP.getThemeIsLight();
  54. log('App', 'isLightTheme: $isLightTheme');
  55. return GetMaterialApp.router(
  56. title: 'ixVPN',
  57. useInheritedMediaQuery: true,
  58. debugShowCheckedModeBanner: Configs.debug,
  59. backButtonDispatcher: IXBackButtonDispatcher(),
  60. getPages: AppPages.routes,
  61. theme: IXTheme.getThemeData(isLight: true),
  62. darkTheme: IXTheme.getThemeData(isLight: false),
  63. themeMode: isLightTheme ? ThemeMode.light : ThemeMode.dark,
  64. fallbackLocale: LocalizationService.defaultLanguage,
  65. locale: IXSP.getCurrentLocal(),
  66. translations: LocalizationService.getInstance(),
  67. builder: (context, widget) => _buildThemedApp(context, widget),
  68. );
  69. }
  70. Widget _buildThemedApp(BuildContext context, Widget? widget) {
  71. return MediaQuery(
  72. data: MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
  73. child: Stack(
  74. children: [
  75. widget!,
  76. Positioned(
  77. top: 0,
  78. right: 0,
  79. width: 100,
  80. height: 100,
  81. child: TripleTapDetector(
  82. requiredTaps: 10,
  83. onTripleTap: () async {
  84. Clipboard.setData(
  85. ClipboardData(text: await DeviceManager.getDeviceId()),
  86. );
  87. IXSnackBar.showIXSnackBar(
  88. title: Strings.copied.tr,
  89. message: await DeviceManager.getDeviceId(),
  90. );
  91. },
  92. child: const SizedBox.shrink(), // 不显示任何东西
  93. ),
  94. ),
  95. Positioned(
  96. top: 0,
  97. left: 0,
  98. width: 100,
  99. height: 100,
  100. child: TripleTapDetector(
  101. requiredTaps: 10,
  102. onTripleTap: () async {
  103. IXDeveloperTools.show();
  104. },
  105. child: const SizedBox.shrink(), // 不显示任何东西
  106. ),
  107. ),
  108. if (Configs.debug)
  109. Positioned(
  110. bottom: 200,
  111. right: 10,
  112. child: ClickOpacity(
  113. child: Container(
  114. width: 40,
  115. height: 40,
  116. decoration: BoxDecoration(
  117. color: Get.reactiveTheme.primaryColor.withValues(
  118. alpha: 0.5,
  119. ),
  120. borderRadius: BorderRadius.circular(40),
  121. ),
  122. child: Icon(Icons.adb, color: Get.reactiveTheme.primaryColor),
  123. ),
  124. onTap: () {
  125. // 使用简化版开发者工具
  126. IXDeveloperTools.show();
  127. },
  128. ),
  129. ),
  130. Positioned(
  131. bottom: 300,
  132. right: 10,
  133. child: ClickOpacity(
  134. child: Container(
  135. width: 40,
  136. height: 40,
  137. decoration: BoxDecoration(
  138. color: Get.reactiveTheme.primaryColor.withValues(alpha: 0.5),
  139. borderRadius: BorderRadius.circular(40),
  140. ),
  141. child: Icon(
  142. ReactiveTheme.isLightTheme ? Icons.sunny : Icons.nightlight,
  143. color: Get.reactiveTheme.primaryColor,
  144. ),
  145. ),
  146. onTap: () {
  147. // 切换主题
  148. IXTheme.changeTheme();
  149. },
  150. ),
  151. ),
  152. ],
  153. ),
  154. );
  155. }
  156. }