node_view.dart 6.5 KB

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