123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:naiyouwl/app/controller/controllers.dart';
- import '../../../component/sys_app_bar.dart';
- import '../controllers/node_controller.dart';
- import 'package:naiyouwl/app/utils/utils.dart';
- class NodeView extends GetView<NodeController> {
- const NodeView({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
- return Container(
- decoration: const BoxDecoration(
- image: DecorationImage(
- image: AssetImage("assets/images/node/nodebg.png"),
- fit: BoxFit.fill,
- ),
- ),
- child: Scaffold(
- backgroundColor: Colors.transparent,
- appBar: SysAppBar(
- title: Text("节点列表"),
- toolbarHeight: kToolbarHeight + 40,
- actions: [
- Row(
- children: [
- IconButton(
- icon: Icon(Icons.refresh),
- onPressed: () {
- controller.pingAllNodes();
- },
- ),
- Text('Ping All'), // 这里是您的标题
- ],
- ),
- ],),
- body: Container(
- width: 376,
- height: 600,
- decoration: const BoxDecoration(
- image: DecorationImage(
- image: AssetImage("assets/images/node/nodetablebg.png"),
- fit: BoxFit.fill,
- ),
- ),
- child: Padding(
- padding: const EdgeInsets.all(30.0),
- child: Column(
- children: [
- // 错误消息展示
- Obx(() {
- if (controller.errorMsg.value.isNotEmpty) {
- return Text(controller.errorMsg.value,
- style: const TextStyle(color: Colors.red));
- }
- return const SizedBox.shrink(); // 返回一个不占空间的widget
- }),
- // 加载指示器
- Obx(() {
- if (controller.isLoading.value) {
- return const CircularProgressIndicator();
- }
- return const SizedBox.shrink();
- }),
- Padding(
- padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- ElevatedButton(
- onPressed: () => controller.filterNodesWithLeastUsersInHK(),
- child: Text('node_auto'.tr),
- ),
- const SizedBox(height: 10,),
- ElevatedButton(
- onPressed: () => controller.showAllNodes(),
- child: Text('node_tit'.tr),
- ),
- // ElevatedButton(
- // onPressed: () => controller.showSelectedFirst(),
- // child: Text("选中的在前"),
- // ),
- // 你可以在这里添加更多的按钮
- ],
- ),
- ),
- Expanded(
- child: Obx(() {
- return RefreshIndicator(
- key: _refreshIndicatorKey,
- onRefresh: controllers.global.fetchNodes,
- child: ListView.builder(
- itemCount: controller.nodesToShow.length,
- itemBuilder: (BuildContext context, int index) {
- final node = controller.nodesToShow[index];
- return Obx(() {
- // print(controller.selectedNode.value?.id);
- // print(
- // controller.selectedNode.value?.id == node.id);
- // // controller.nodeModes[controller.selectedIndex.value]
- // print("node ---- ${node.id} index ---- $index");
- bool isNodeLoading = controller.isLoadingMap[node
- .id] ?? false;
- var pingResult = controller.pingResults[node
- .id] ??
- '';
- var type = node.type;
- if(node.vless == 1){
- type = "vless";
- }
- var trafficRate = node.trafficRate;
- var leables = node.leables;
- return Container(
- color: controllers.global.selectedNode.value?.id ==
- node.id ? Colors.black12 : null,
- child: ListTile(
- key: ValueKey(node.id),
- title: Text(node.name.toString()),
- //tileColor: controller.selectedNode.value?.id == node.id ? Colors.blueAccent : null,
- // 如果选中则更改背景颜色
- subtitle: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text("$trafficRate倍速率 $type",
- style: TextStyle(
- fontSize: 10.0, // 设置字体大小为 20.0
- ),
- ),
- SizedBox(height: 4,),
- Text(
- leables ?? "",
- style: TextStyle(
- fontSize: 10.0, // 设置字体大小为 20.0
- ),
- )
- ],
- ),
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (isNodeLoading)
- const CircularProgressIndicator(),
- if (!isNodeLoading) ...[
- Text(pingResult),
- ElevatedButton(
- onPressed: () {
- controller.pingSingleNode(node);
- },
- child: const Text('测速'),
- ),
- ],
- ],
- ),
- onTap: () {
- controller.selectNode(node);
- },
- ),
- );
- });
- },
- ),
- );
- }),
- ),
- ],
- ),
- ),
- )
- ),
- );
- }
- }
|