node_view.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. return Container(
  112. color: controllers.global.selectedNode.value?.id ==
  113. node.id ? Colors.black12 : null,
  114. child: ListTile(
  115. key: ValueKey(node.id),
  116. title: Text(node.name.toString()),
  117. //tileColor: controller.selectedNode.value?.id == node.id ? Colors.blueAccent : null,
  118. // 如果选中则更改背景颜色
  119. subtitle: Text(type ?? ""),
  120. trailing: Row(
  121. mainAxisSize: MainAxisSize.min,
  122. children: [
  123. if (isNodeLoading)
  124. const CircularProgressIndicator(),
  125. if (!isNodeLoading) ...[
  126. Text(pingResult),
  127. ElevatedButton(
  128. onPressed: () {
  129. controller.pingSingleNode(node);
  130. },
  131. child: const Text('测速'),
  132. ),
  133. ],
  134. ],
  135. ),
  136. onTap: () {
  137. controller.selectNode(node);
  138. },
  139. ),
  140. );
  141. });
  142. },
  143. ),
  144. );
  145. }),
  146. ),
  147. ],
  148. ),
  149. ),
  150. )
  151. ),
  152. );
  153. }
  154. }