routingmode_view.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/app/base/base_view.dart';
  5. import 'package:nomo/app/widgets/click_opacity.dart';
  6. import 'package:nomo/app/widgets/ix_app_bar.dart';
  7. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  8. import '../controllers/routingmode_controller.dart';
  9. class RoutingmodeView extends BaseView<RoutingmodeController> {
  10. const RoutingmodeView({super.key});
  11. @override
  12. PreferredSizeWidget? get appBar => IXAppBar(title: 'Routing Mode');
  13. @override
  14. Widget buildContent(BuildContext context) {
  15. return Padding(
  16. padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.w),
  17. child: Container(
  18. decoration: BoxDecoration(
  19. color: Get.reactiveTheme.highlightColor,
  20. borderRadius: BorderRadius.circular(12.r),
  21. ),
  22. child: Obx(
  23. () => Column(
  24. mainAxisSize: MainAxisSize.min,
  25. children: [
  26. _buildRoutingOption(
  27. mode: RoutingMode.smart,
  28. icon: Icons.flash_on,
  29. title: 'Smart',
  30. description:
  31. 'The local and VPN networks coexist, and the optimal route is selected intelligently.',
  32. isSelected: controller.selectedMode.value == RoutingMode.smart,
  33. onTap: () => controller.selectMode(RoutingMode.smart),
  34. ),
  35. _buildDivider(),
  36. _buildRoutingOption(
  37. mode: RoutingMode.global,
  38. icon: Icons.language,
  39. title: 'Global',
  40. description:
  41. 'All traffic is routed through the VPN server to ensure maximum privacy and security.',
  42. isSelected: controller.selectedMode.value == RoutingMode.global,
  43. onTap: () => controller.selectMode(RoutingMode.global),
  44. ),
  45. ],
  46. ),
  47. ),
  48. ),
  49. );
  50. }
  51. /// 构建路由选项
  52. Widget _buildRoutingOption({
  53. required RoutingMode mode,
  54. required IconData icon,
  55. required String title,
  56. required String description,
  57. required bool isSelected,
  58. required VoidCallback onTap,
  59. }) {
  60. return ClickOpacity(
  61. onTap: onTap,
  62. child: Padding(
  63. padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
  64. child: Row(
  65. crossAxisAlignment: CrossAxisAlignment.start,
  66. children: [
  67. // 图标
  68. Container(
  69. width: 30.w,
  70. height: 30.w,
  71. decoration: BoxDecoration(
  72. color: Get.reactiveTheme.shadowColor,
  73. borderRadius: BorderRadius.circular(8.r),
  74. ),
  75. child: Icon(icon, color: Colors.white, size: 20.w),
  76. ),
  77. 10.horizontalSpace,
  78. // 标题和描述
  79. Expanded(
  80. child: Column(
  81. crossAxisAlignment: CrossAxisAlignment.start,
  82. children: [
  83. Text(
  84. title,
  85. style: TextStyle(
  86. fontSize: 14.sp,
  87. height: 1.4,
  88. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  89. ),
  90. ),
  91. Text(
  92. description,
  93. style: TextStyle(
  94. fontSize: 12.sp,
  95. color: Get.reactiveTheme.hintColor,
  96. height: 1.6,
  97. ),
  98. ),
  99. ],
  100. ),
  101. ),
  102. 10.horizontalSpace,
  103. // 选中指示器
  104. Container(
  105. width: 20.w,
  106. height: 20.w,
  107. decoration: BoxDecoration(
  108. shape: BoxShape.circle,
  109. color: isSelected
  110. ? Get.reactiveTheme.shadowColor
  111. : Colors.transparent,
  112. border: Border.all(
  113. color: isSelected
  114. ? Get.reactiveTheme.shadowColor
  115. : Colors.grey[400]!,
  116. width: 2.w,
  117. ),
  118. ),
  119. child: isSelected
  120. ? Icon(Icons.check, color: Colors.white, size: 16.w)
  121. : null,
  122. ),
  123. ],
  124. ),
  125. ),
  126. );
  127. }
  128. /// 构建分割线
  129. Widget _buildDivider() {
  130. return Divider(color: Get.reactiveTheme.dividerColor, height: 1.w);
  131. }
  132. }