splittunneling_view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. import 'package:nomo/app/base/base_view.dart';
  6. import 'package:nomo/app/constants/iconfont/iconfont.dart';
  7. import 'package:nomo/app/widgets/click_opacity.dart';
  8. import 'package:nomo/app/widgets/ix_app_bar.dart';
  9. import 'package:nomo/app/widgets/ix_image.dart';
  10. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  11. import '../../../../config/translations/strings_enum.dart';
  12. import '../controllers/splittunneling_controller.dart';
  13. import '../selectapp/controllers/splittunneling_selectapp_controller.dart';
  14. class SplittunnelingView extends BaseView<SplittunnelingController> {
  15. const SplittunnelingView({super.key});
  16. @override
  17. PreferredSizeWidget? get appBar => IXAppBar(title: Strings.splitTunneling.tr);
  18. @override
  19. Widget buildContent(BuildContext context) {
  20. return Column(
  21. children: [
  22. Expanded(
  23. child: SingleChildScrollView(
  24. padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.w),
  25. child: Column(
  26. crossAxisAlignment: CrossAxisAlignment.start,
  27. children: [
  28. // 顶部提示框
  29. _buildAlertBox(),
  30. 10.verticalSpaceFromWidth,
  31. // 模式选择区域
  32. _buildModeSelection(),
  33. ],
  34. ),
  35. ),
  36. ),
  37. // 底部信息框
  38. SafeArea(child: _buildInfoBox()),
  39. ],
  40. );
  41. }
  42. /// 构建顶部提示框
  43. Widget _buildAlertBox() {
  44. return Container(
  45. padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.w),
  46. decoration: BoxDecoration(
  47. color: Get.reactiveTheme.cardColor,
  48. borderRadius: BorderRadius.circular(12.r),
  49. ),
  50. child: Row(
  51. children: [
  52. Icon(IconFont.icon67, size: 20.w, color: const Color(0xFFFFB800)),
  53. SizedBox(width: 12.w),
  54. Expanded(
  55. child: Text(
  56. Strings.onlyOneModeActive.tr,
  57. style: TextStyle(
  58. fontSize: 12.sp,
  59. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  60. fontWeight: FontWeight.w500,
  61. ),
  62. ),
  63. ),
  64. ],
  65. ),
  66. );
  67. }
  68. /// 构建模式选择区域
  69. Widget _buildModeSelection() {
  70. return Column(
  71. children: [
  72. _buildModeCard(
  73. mode: SplitTunnelingMode.exclude,
  74. icon: IconFont.icon42,
  75. title: Strings.excludeSelectedAppsFromVPN.tr,
  76. description: Strings.chooseAppsExcludeDesc.tr,
  77. onTap: () {
  78. controller.selectMode(SplitTunnelingMode.exclude);
  79. // 刷新显示
  80. controller.refreshSelectedApps();
  81. },
  82. ),
  83. 10.verticalSpaceFromWidth,
  84. _buildModeCard(
  85. mode: SplitTunnelingMode.include,
  86. icon: IconFont.icon43,
  87. title: Strings.useVPNForSelectedAppsOnly.tr,
  88. description: Strings.chooseAppsIncludeDesc.tr,
  89. onTap: () {
  90. controller.selectMode(SplitTunnelingMode.include);
  91. // 刷新显示
  92. controller.refreshSelectedApps();
  93. },
  94. ),
  95. ],
  96. );
  97. }
  98. /// 构建模式卡片
  99. Widget _buildModeCard({
  100. required SplitTunnelingMode mode,
  101. required IconData icon,
  102. required String title,
  103. required String description,
  104. required VoidCallback onTap,
  105. }) {
  106. return Container(
  107. decoration: BoxDecoration(
  108. color: Get.reactiveTheme.highlightColor,
  109. borderRadius: BorderRadius.circular(12.r),
  110. ),
  111. child: Column(
  112. children: [
  113. ClickOpacity(
  114. onTap: onTap,
  115. child: Padding(
  116. padding: EdgeInsets.all(14.w),
  117. child: Row(
  118. crossAxisAlignment: CrossAxisAlignment.start,
  119. children: [
  120. // 图标
  121. Container(
  122. width: 30.w,
  123. height: 30.w,
  124. decoration: BoxDecoration(
  125. color: Get.reactiveTheme.shadowColor,
  126. borderRadius: BorderRadius.circular(8.r),
  127. ),
  128. child: Icon(icon, color: Colors.white, size: 20.w),
  129. ),
  130. 10.horizontalSpace,
  131. // 标题和描述
  132. Expanded(
  133. child: Column(
  134. crossAxisAlignment: CrossAxisAlignment.start,
  135. children: [
  136. Text(
  137. title,
  138. style: TextStyle(
  139. fontSize: 14.sp,
  140. height: 1.4,
  141. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  142. ),
  143. ),
  144. Text(
  145. description,
  146. style: TextStyle(
  147. fontSize: 12.sp,
  148. height: 1.6,
  149. color: Get.reactiveTheme.hintColor,
  150. ),
  151. ),
  152. ],
  153. ),
  154. ),
  155. 10.horizontalSpace,
  156. // Switch 开关
  157. Obx(() {
  158. final isSelected = controller.selectedMode.value == mode;
  159. return CupertinoSwitch(
  160. value: isSelected,
  161. onChanged: (value) {
  162. if (value) {
  163. controller.selectMode(mode);
  164. } else {
  165. controller.selectMode(SplitTunnelingMode.none);
  166. }
  167. controller.refreshSelectedApps();
  168. },
  169. activeTrackColor: Get.reactiveTheme.shadowColor,
  170. thumbColor: Colors.white,
  171. inactiveThumbColor: Colors.white,
  172. inactiveTrackColor: Colors.grey,
  173. );
  174. }),
  175. ],
  176. ),
  177. ),
  178. ),
  179. // 显示选中的应用
  180. Obx(() {
  181. final isSelected = controller.selectedMode.value == mode;
  182. if (isSelected) {
  183. final selectedApps = controller.getSelectedApps(mode);
  184. if (selectedApps.isNotEmpty) {
  185. return _buildSelectedAppsPreview(selectedApps);
  186. }
  187. }
  188. return const SizedBox.shrink();
  189. }),
  190. ],
  191. ),
  192. );
  193. }
  194. /// 构建选中应用预览
  195. Widget _buildSelectedAppsPreview(List<Map<String, dynamic>> selectedApps) {
  196. return AnimatedContainer(
  197. duration: const Duration(milliseconds: 300),
  198. curve: Curves.easeInOut,
  199. child: ClickOpacity(
  200. onTap: () {
  201. controller.toSelectAppPage(controller.selectedMode.value);
  202. },
  203. child: Container(
  204. height: 44.w,
  205. padding: EdgeInsets.symmetric(horizontal: 16.w),
  206. decoration: BoxDecoration(
  207. color: Get.reactiveTheme.cardColor,
  208. borderRadius: BorderRadius.only(
  209. bottomLeft: Radius.circular(12.r),
  210. bottomRight: Radius.circular(12.r),
  211. ),
  212. ),
  213. child: Row(
  214. children: [
  215. Text(
  216. Strings.selectApps.tr,
  217. style: TextStyle(
  218. fontSize: 12.sp,
  219. color: Get.reactiveTheme.hintColor,
  220. fontWeight: FontWeight.w500,
  221. ),
  222. ),
  223. SizedBox(width: 8.w),
  224. Expanded(
  225. child: Row(
  226. mainAxisAlignment: MainAxisAlignment.end,
  227. children: [
  228. // 显示应用图标
  229. ...selectedApps
  230. .take(3)
  231. .toList()
  232. .asMap()
  233. .entries
  234. .map(
  235. (entry) => AnimatedContainer(
  236. duration: Duration(
  237. milliseconds: 200 + (entry.key * 100),
  238. ),
  239. curve: Curves.easeOut,
  240. margin: EdgeInsets.only(right: 6.w),
  241. child: SlideTransition(
  242. position:
  243. Tween<Offset>(
  244. begin: const Offset(0, 1),
  245. end: Offset.zero,
  246. ).animate(
  247. CurvedAnimation(
  248. parent: kAlwaysCompleteAnimation,
  249. curve: Curves.easeOut,
  250. ),
  251. ),
  252. child: FadeTransition(
  253. opacity: Tween<double>(begin: 0.0, end: 1.0)
  254. .animate(
  255. CurvedAnimation(
  256. parent: kAlwaysCompleteAnimation,
  257. curve: Curves.easeOut,
  258. ),
  259. ),
  260. child: ClipRRect(
  261. borderRadius: BorderRadius.circular(4.r),
  262. child: IXImage(
  263. key: ValueKey(
  264. 'preview_${entry.value['packageName']}',
  265. ),
  266. source: entry.value['icon'],
  267. width: 24.w,
  268. height: 24.w,
  269. sourceType: ImageSourceType.memory,
  270. ),
  271. ),
  272. ),
  273. ),
  274. ),
  275. ),
  276. // 如果有更多应用,显示箭头
  277. if (selectedApps.length > 3) ...[
  278. SizedBox(width: 4.w),
  279. AnimatedScale(
  280. scale: 1.0,
  281. duration: const Duration(milliseconds: 300),
  282. curve: Curves.easeOut,
  283. child: Icon(
  284. Icons.arrow_forward_ios,
  285. size: 12.w,
  286. color: Get.reactiveTheme.hintColor,
  287. ),
  288. ),
  289. ],
  290. ],
  291. ),
  292. ),
  293. AnimatedRotation(
  294. turns: 0.0,
  295. duration: const Duration(milliseconds: 200),
  296. child: Icon(
  297. Icons.keyboard_arrow_right,
  298. size: 20.w,
  299. color: Get.reactiveTheme.hintColor,
  300. ),
  301. ),
  302. ],
  303. ),
  304. ),
  305. ),
  306. );
  307. }
  308. /// 构建底部信息框
  309. Widget _buildInfoBox() {
  310. return Container(
  311. margin: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.w),
  312. padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.w),
  313. decoration: BoxDecoration(
  314. color: Get.reactiveTheme.canvasColor,
  315. borderRadius: BorderRadius.circular(12.r),
  316. ),
  317. child: Column(
  318. children: [
  319. Row(
  320. children: [
  321. Icon(
  322. IconFont.icon22,
  323. size: 20.w,
  324. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  325. ),
  326. 4.horizontalSpace,
  327. Text(
  328. Strings.customizeYourVPN.tr,
  329. style: TextStyle(
  330. fontSize: 14.sp,
  331. height: 1.6,
  332. fontWeight: FontWeight.w500,
  333. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  334. ),
  335. ),
  336. ],
  337. ),
  338. 10.verticalSpaceFromWidth,
  339. Text(
  340. Strings.splitTunnelingDesc.tr,
  341. style: TextStyle(
  342. fontSize: 12.sp,
  343. color: Get.reactiveTheme.hintColor,
  344. height: 1.6,
  345. ),
  346. ),
  347. ],
  348. ),
  349. );
  350. }
  351. }