node_view.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:naiyouwl/app/controller/controllers.dart';
  4. import '../../../component/sys_app_bar.dart';
  5. import '../controllers/node_controller.dart';
  6. import 'package:naiyouwl/app/utils/utils.dart';
  7. class NodeView extends GetView<NodeController> {
  8. const NodeView({Key? key}) : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
  12. return Container(
  13. decoration: const BoxDecoration(
  14. image: DecorationImage(
  15. image: AssetImage("assets/images/node/nodebg.png"),
  16. fit: BoxFit.fill,
  17. ),
  18. ),
  19. child: Scaffold(
  20. backgroundColor: Colors.transparent,
  21. appBar: SysAppBar(
  22. title: Text("节点列表"),
  23. toolbarHeight: kToolbarHeight + 40,
  24. actions: [
  25. Row(
  26. children: [
  27. IconButton(
  28. icon: Icon(Icons.refresh),
  29. onPressed: () {
  30. controller.pingAllNodes();
  31. },
  32. ),
  33. Text('Ping All'), // 这里是您的标题
  34. ],
  35. ),
  36. ],),
  37. body: Container(
  38. width: 376,
  39. height: 600,
  40. decoration: const BoxDecoration(
  41. image: DecorationImage(
  42. image: AssetImage("assets/images/node/nodetablebg.png"),
  43. fit: BoxFit.fill,
  44. ),
  45. ),
  46. child: Padding(
  47. padding: const EdgeInsets.all(30.0),
  48. child: Column(
  49. children: [
  50. // 错误消息展示
  51. Obx(() {
  52. if (controller.errorMsg.value.isNotEmpty) {
  53. return Text(controller.errorMsg.value,
  54. style: const TextStyle(color: Colors.red));
  55. }
  56. return const SizedBox.shrink(); // 返回一个不占空间的widget
  57. }),
  58. // 加载指示器
  59. Obx(() {
  60. if (controller.isLoading.value) {
  61. return const CircularProgressIndicator();
  62. }
  63. return const SizedBox.shrink();
  64. }),
  65. Padding(
  66. padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
  67. child: Column(
  68. mainAxisAlignment: MainAxisAlignment.spaceAround,
  69. children: [
  70. ElevatedButton(
  71. onPressed: () => controller.filterNodesWithLeastUsersInHK(),
  72. child: Text('node_auto'.tr),
  73. ),
  74. const SizedBox(height: 10,),
  75. ElevatedButton(
  76. onPressed: () => controller.showAllNodes(),
  77. child: Text('node_tit'.tr),
  78. ),
  79. // ElevatedButton(
  80. // onPressed: () => controller.showSelectedFirst(),
  81. // child: Text("选中的在前"),
  82. // ),
  83. // 你可以在这里添加更多的按钮
  84. ],
  85. ),
  86. ),
  87. Expanded(
  88. child: Obx(() {
  89. return RefreshIndicator(
  90. key: _refreshIndicatorKey,
  91. onRefresh: controllers.global.fetchNodes,
  92. child: ListView.builder(
  93. itemCount: controller.nodesToShow.length,
  94. itemBuilder: (BuildContext context, int index) {
  95. final node = controller.nodesToShow[index];
  96. return Obx(() {
  97. // print(controller.selectedNode.value?.id);
  98. // print(
  99. // controller.selectedNode.value?.id == node.id);
  100. // // controller.nodeModes[controller.selectedIndex.value]
  101. // print("node ---- ${node.id} index ---- $index");
  102. bool isNodeLoading = controller.isLoadingMap[node
  103. .id] ?? false;
  104. var pingResult = controller.pingResults[node
  105. .id] ??
  106. '';
  107. var type = node.type;
  108. if(node.vless == 1){
  109. type = "vless";
  110. }
  111. var trafficRate = node.trafficRate;
  112. var leables = node.leables;
  113. return Container(
  114. color: controllers.global.selectedNode.value?.id ==
  115. node.id ? Colors.black12 : null,
  116. child: ListTile(
  117. key: ValueKey(node.id),
  118. title: Text(node.name.toString()),
  119. //tileColor: controller.selectedNode.value?.id == node.id ? Colors.blueAccent : null,
  120. // 如果选中则更改背景颜色
  121. subtitle: Column(
  122. crossAxisAlignment: CrossAxisAlignment.start,
  123. children: [
  124. Text("$trafficRate倍速率 $type",
  125. style: TextStyle(
  126. fontSize: 10.0, // 设置字体大小为 20.0
  127. ),
  128. ),
  129. SizedBox(height: 4,),
  130. Text(
  131. leables ?? "",
  132. style: TextStyle(
  133. fontSize: 10.0, // 设置字体大小为 20.0
  134. ),
  135. )
  136. ],
  137. ),
  138. trailing: Row(
  139. mainAxisSize: MainAxisSize.min,
  140. children: [
  141. if (isNodeLoading)
  142. const CircularProgressIndicator(),
  143. if (!isNodeLoading) ...[
  144. Text(pingResult),
  145. ElevatedButton(
  146. onPressed: () {
  147. controller.pingSingleNode(node);
  148. },
  149. child: const Text('测速'),
  150. ),
  151. ],
  152. ],
  153. ),
  154. onTap: () {
  155. controller.selectNode(node);
  156. },
  157. ),
  158. );
  159. });
  160. },
  161. ),
  162. );
  163. }),
  164. ),
  165. ],
  166. ),
  167. ),
  168. )
  169. ),
  170. );
  171. }
  172. }