node_view.dart 6.3 KB

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