feat: 节点测速调整

This commit is contained in:
2025-11-26 19:23:15 -08:00
parent 909020654f
commit b059d01556
6 changed files with 513 additions and 740 deletions
@@ -26,13 +26,14 @@ class HINodeListView extends GetView<HINodeListController> {
/// 获取分组内最快节点的延迟值(单位:ms)
/// 如果列表为空,返回 0
int getFastestNodeDelay(
HINodeListController controller,
List<KROutboundItem> outboundList,
) {
HINodeListController controller,
List<KROutboundItem> outboundList,
) {
if (outboundList.isEmpty) return 0;
// 返回最小延迟值
outboundList.sort((a, b) => a.urlTestDelay.value.compareTo(b.urlTestDelay.value));
outboundList
.sort((a, b) => a.urlTestDelay.value.compareTo(b.urlTestDelay.value));
return outboundList.first.urlTestDelay.value;
}
@@ -152,36 +153,39 @@ class HINodeListView extends GetView<HINodeListController> {
],
),
),
Obx(() => controller.homeController.kr_coutryText.value == 'auto'
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
Obx(() =>
controller.homeController.kr_cutSeletedTag.value ==
'auto'
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
],
),
),
),
...controller.kr_subscribeService.countryOutboundList.map((country) {
...controller.kr_subscribeService.countryOutboundList
.map((country) {
return InkWell(
onTap: () async {
try {
final success =
await controller.homeController.kr_performNodeSwitch('auto');
final fastest = findFastestNode(country.outboundList);
final success = await controller.homeController
.kr_performNodeSwitch(fastest.tag);
if (success) {
controller.homeController.kr_currentListStatus.value =
KRHomeViewsListStatus.kr_none;
}
} catch (e) {
KRLogUtil.kr_e('Auto选项切换异常: $e',
tag: 'NodeListView');
KRLogUtil.kr_e('国家选择切换异常: $e', tag: 'NodeListView');
}
},
child: _kr_buildCountryListItem(context, country: country),
@@ -189,86 +193,87 @@ class HINodeListView extends GetView<HINodeListController> {
}).toList(),
]
] //
),
),
);
});
}
/// 构建默认的订阅节点列表
Widget _buildSubscribeList(BuildContext context) {
return Obx(() {
return _kr_buildListContainer(
context,
child: ListView(
padding: EdgeInsets.symmetric(vertical: 8.w),
// 2. 使用 children 属性,并一次性构建所有列表项
children: [
...[
InkWell(
// 🔧 修复:改为 async,等待节点切换完成后再关闭列表
onTap: () async {
try {
final success =
await controller.homeController.kr_performNodeSwitch('auto');
if (success) {
controller.homeController.kr_currentListStatus.value =
KRHomeViewsListStatus.kr_none;
}
} catch (e) {
KRLogUtil.kr_e('Auto选项切换异常: $e',
tag: 'NodeListView');
}
},
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.white.withOpacity(0.3),
width: 1.0,
),
),
),
padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 16.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 32.w,
height: 22.w,
padding: EdgeInsets.symmetric(vertical: 8.w),
// 2. 使用 children 属性,并一次性构建所有列表项
children: [
...[
InkWell(
// 🔧 修复:改为 async,等待节点切换完成后再关闭列表
onTap: () async {
try {
final success = await controller.homeController
.kr_performNodeSwitch('auto');
if (success) {
controller.homeController.kr_currentListStatus.value =
KRHomeViewsListStatus.kr_none;
}
} catch (e) {
KRLogUtil.kr_e('Auto选项切换异常: $e', tag: 'NodeListView');
}
},
child: Container(
decoration: BoxDecoration(
// 2. 设置背景色为主题色
color: Theme.of(context).primaryColor,
),
// 4. 使用 Center 来确保内部的图片水平和垂直居中
child: Center(
child: KrLocalImage(
imageName: "hi-home-logo",
width: 14.w,
height: 14.h,
border: Border(
bottom: BorderSide(
color: Colors.white.withOpacity(0.3),
width: 1.0,
),
),
),
),
SizedBox(width: 8.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
padding:
EdgeInsets.symmetric(vertical: 12.w, horizontal: 16.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'自动匹配最快网络', // 您指定的文本
style: KrAppTextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w600, // 600 加粗
Container(
width: 32.w,
height: 22.w,
decoration: BoxDecoration(
// 2. 设置背景色为主题色
color: Theme.of(context).primaryColor,
),
// 4. 使用 Center 来确保内部的图片水平和垂直居中
child: Center(
child: KrLocalImage(
imageName: "hi-home-logo",
width: 14.w,
height: 14.h,
),
),
),
// 2. 第二个 Text: "根据网络IP自动匹配最快线路"
Text(
'根据网络IP自动匹配最快线路', // 默认文本
style: KrAppTextStyle(
fontSize: 10,
color: Colors.white,
),
),
/* Obx(() {
SizedBox(width: 8.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'自动匹配最快网络', // 您指定的文本
style: KrAppTextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w600, // 600 加粗
),
),
// 2. 第二个 Text: "根据网络IP自动匹配最快线路"
Text(
'根据网络IP自动匹配最快线路', // 默认文本
style: KrAppTextStyle(
fontSize: 10,
color: Colors.white,
),
),
/* Obx(() {
// 当选择全局 auto 时,显示当前选中的节点信息
if (controller.homeController.kr_cutTag.value == 'auto') {
final autoNodeInfo = controller.homeController.kr_getGlobalAutoSelectedNode();
@@ -290,51 +295,49 @@ class HINodeListView extends GetView<HINodeListController> {
),
);
}),*/
],
),
),
Obx(() =>
controller.homeController.kr_cutTag.value == 'auto'
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
],
),
),
Obx(() => controller.homeController.kr_cutTag.value == 'auto'
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
],
),
),
...controller.kr_subscribeService.allList().map((item) {
return InkWell(
// 🔧 修复:改为 async,等待节点切换完成后再关闭列表
onTap: () async {
try {
KRLogUtil.kr_i('🔄 用户点击节点: ${item.tag}');
final success = await controller.homeController
.kr_performNodeSwitch(item.tag);
if (success) {
controller.homeController.kr_currentListStatus.value =
KRHomeViewsListStatus.kr_none;
}
} catch (e) {
KRLogUtil.kr_e('节点切换异常: $e', tag: 'NodeListView');
}
},
child: _kr_buildNodeListItem(context, item: item),
);
}).toList(),
]
] //
),
),
...controller.kr_subscribeService.allList().map((item) {
return InkWell(
// 🔧 修复:改为 async,等待节点切换完成后再关闭列表
onTap: () async {
try {
KRLogUtil.kr_i(
'🔄 用户点击节点: ${item.tag}');
final success = await controller.homeController
.kr_performNodeSwitch(item.tag);
if (success) {
controller.homeController.kr_currentListStatus.value =
KRHomeViewsListStatus.kr_none;
}
} catch (e) {
KRLogUtil.kr_e(
'节点切换异常: $e',
tag: 'NodeListView');
}
},
child: _kr_buildNodeListItem(context, item: item),
);
}).toList(),
]
] //
),
);
});
}
@@ -346,7 +349,8 @@ class HINodeListView extends GetView<HINodeListController> {
alignment: Alignment.center,
child: Text(
text,
style: KrAppTextStyle(fontSize: 14, color: Theme.of(context).textTheme.bodySmall?.color),
style: KrAppTextStyle(
fontSize: 14, color: Theme.of(context).textTheme.bodySmall?.color),
),
);
}
@@ -363,7 +367,8 @@ class HINodeListView extends GetView<HINodeListController> {
}
/// 构建单个节点列表项的UI
Widget _kr_buildNodeListItem(BuildContext context, {required KROutboundItem item}) {
Widget _kr_buildNodeListItem(BuildContext context,
{required KROutboundItem item}) {
return Container(
key: ValueKey(item.id),
decoration: BoxDecoration(
@@ -378,7 +383,12 @@ class HINodeListView extends GetView<HINodeListController> {
padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 16.w),
child: Row(
children: [
KRCountryFlag(countryCode: item.country, width: 30.w, height: 20.w, isCircle: false, maintainSize: false),
KRCountryFlag(
countryCode: item.country,
width: 30.w,
height: 20.w,
isCircle: false,
maintainSize: false),
SizedBox(width: 12.w),
Expanded(
child: Obx(() {
@@ -404,7 +414,8 @@ class HINodeListView extends GetView<HINodeListController> {
bool isTesting = controller.homeController.kr_isLatency.value;
// 极简逻辑:只根据节点类型决定显示方式
print('🔄 _kr_buildNodeListItem节点: item.tag=${item.tag}, country=${item.country}');
print(
'🔄 _kr_buildNodeListItem节点: item.tag=${item.tag}, country=${item.country}');
// 普通节点,直接显示节点自身的速度
displayDelay = item.urlTestDelay.value;
@@ -441,19 +452,23 @@ class HINodeListView extends GetView<HINodeListController> {
);
}),
SizedBox(width: 12.w),
Obx(() => controller.homeController.kr_cutTag.value == item.tag
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
Obx(() {
final selected =
controller.homeController.kr_cutSeletedTag.value == item.tag;
return selected
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w,
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w,
height: 16.h,
);
}),
],
),
);
@@ -461,7 +476,6 @@ class HINodeListView extends GetView<HINodeListController> {
/// 构建国家列表项的UI
Widget _kr_buildCountryListItem(BuildContext context, {required country}) {
return Container(
key: ValueKey(country),
decoration: BoxDecoration(
@@ -476,17 +490,26 @@ class HINodeListView extends GetView<HINodeListController> {
padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 16.w),
child: Row(
children: [
KRCountryFlag(countryCode: country.country, width: 30.w, height: 20.w, isCircle: false, maintainSize: false),
KRCountryFlag(
countryCode: country.country,
width: 30.w,
height: 20.w,
isCircle: false,
maintainSize: false),
SizedBox(width: 12.w),
Expanded(
child: Text(
controller.homeController.kr_getCountryFullName(country.country),
style: KrAppTextStyle(fontSize: 16, fontWeight: FontWeight.w500, color: Colors.white),
style: KrAppTextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white),
),
),
Obx(() {
// 1. 获取延迟值和测速状态
int displayDelay = getFastestNodeDelay(controller, country.outboundList);
int displayDelay =
getFastestNodeDelay(controller, country.outboundList);
bool isTesting = controller.homeController.kr_isLatency.value;
// 2. 声明文本和颜色变量
@@ -520,21 +543,36 @@ class HINodeListView extends GetView<HINodeListController> {
);
}),
SizedBox(width: 12.w),
Obx(() => controller.homeController.kr_cutTag.value == '${country.country}-auto'
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w, // 适当缩小 SVG 尺寸,留出白边
height: 16.h,
)),
Obx(() {
final selectedTag =
controller.homeController.kr_cutSeletedTag.value;
if (selectedTag == 'auto') {
return KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w,
height: 16.h,
);
}
final node = controller.kr_subscribeService.keyList[selectedTag];
final selectedCountry = node?.country ?? '';
final selected = selectedCountry == country.country;
return selected
? KrLocalImage(
imageName: 'radio-active-icon',
imageType: ImageType.svg,
width: 16.w,
height: 16.h,
)
: KrLocalImage(
imageName: 'radio-icon',
imageType: ImageType.svg,
width: 16.w,
height: 16.h,
);
}),
],
),
);
}
}
}