node_view.dart 6.3 KB

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