- vpnStatsProvider:暴露内核 statsStream(上/下行瞬时速率);连接页速度行 下/上行改用实时数据(B/s→Mb/s),不再硬编码 86.4/12.1;延迟用实测节点 ping。 - ConnectionState 加 error 字段;_connect 失败不再静默回 off,而是按语言 冒泡 ConnectApiException 文案;节点未就绪(无 uuid)给出提示并删除旧 1.2s mock 连接路径。 - 连接页 caption 下/桌面 pill 上方显示错误文案(红)。 - 重写 connection_controller_test 适配(无网络:未就绪→off+error)。 flutter analyze 0 error;114 tests passed。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,9 @@ class ConnectPage extends ConsumerWidget {
|
||||
final smart = ref.watch(isSmartSelectProvider);
|
||||
final isFree = ref.watch(isFreePlanProvider);
|
||||
final quota = ref.watch(quotaProvider);
|
||||
final stats = ref.watch(vpnStatsProvider).valueOrNull;
|
||||
final down = _mbps(stats?.downloadSpeed);
|
||||
final up = _mbps(stats?.uploadSpeed);
|
||||
|
||||
final caption = switch (conn.phase) {
|
||||
VpnPhase.off => t.capOff,
|
||||
@@ -46,13 +49,23 @@ class ConnectPage extends ConsumerWidget {
|
||||
onTap: () => ref.read(connectionProvider.notifier).toggle(),
|
||||
);
|
||||
|
||||
final captionWidget = Text(caption,
|
||||
style: PangolinText.body.copyWith(color: c.fg2, fontWeight: FontWeight.w600));
|
||||
final captionWidget = Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Text(caption, style: PangolinText.body.copyWith(color: c.fg2, fontWeight: FontWeight.w600)),
|
||||
if (conn.error != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(conn.error!,
|
||||
textAlign: TextAlign.center,
|
||||
style: PangolinText.caption.copyWith(color: c.danger, fontWeight: FontWeight.w500)),
|
||||
),
|
||||
],
|
||||
]);
|
||||
|
||||
final infoChildren = <Widget>[
|
||||
if (isFree)
|
||||
QuotaCard(quota: quota, t: t, onWatchAd: () => ref.read(quotaProvider.notifier).watchAd()),
|
||||
if (conn.phase == VpnPhase.on) _SpeedRow(t: t, node: node),
|
||||
if (conn.phase == VpnPhase.on) _SpeedRow(t: t, node: node, down: down, up: up),
|
||||
_CurrentNodeCard(t: t, node: node, smart: smart, showLabel: isWide, onTap: onOpenNodes),
|
||||
];
|
||||
|
||||
@@ -83,6 +96,14 @@ class ConnectPage extends ConsumerWidget {
|
||||
textAlign: TextAlign.center,
|
||||
style: PangolinText.display.copyWith(color: c.fg1, fontSize: 22, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 10),
|
||||
if (conn.error != null) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(conn.error!,
|
||||
textAlign: TextAlign.center,
|
||||
style: PangolinText.caption.copyWith(color: c.danger, fontWeight: FontWeight.w500)),
|
||||
),
|
||||
],
|
||||
_NodePill(t: t, node: node, smart: smart),
|
||||
if (isFree) ...[
|
||||
const SizedBox(height: 24),
|
||||
@@ -93,7 +114,7 @@ class ConnectPage extends ConsumerWidget {
|
||||
],
|
||||
if (conn.phase == VpnPhase.on) ...[
|
||||
const SizedBox(height: 16),
|
||||
_SpeedRow(t: t, node: node),
|
||||
_SpeedRow(t: t, node: node, down: down, up: up),
|
||||
],
|
||||
]),
|
||||
),
|
||||
@@ -174,18 +195,24 @@ class ConnectPage extends ConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 实时速率行(连接成功时显示;演示值)。
|
||||
/// 字节/秒 → Mb/s 字符串(null = 未取到,显示 —)。
|
||||
String _mbps(double? bytesPerSec) =>
|
||||
bytesPerSec == null ? '—' : (bytesPerSec * 8 / 1000000).toStringAsFixed(1);
|
||||
|
||||
/// 实时速率行(连接成功时显示;来自内核 statsStream 实时数据)。
|
||||
class _SpeedRow extends StatelessWidget {
|
||||
const _SpeedRow({required this.t, required this.node});
|
||||
const _SpeedRow({required this.t, required this.node, required this.down, required this.up});
|
||||
final AppText t;
|
||||
final Node node;
|
||||
final String down;
|
||||
final String up;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.pangolin;
|
||||
final metrics = [
|
||||
(PangolinIcons.arrowDown, t.download, '86.4', 'Mb/s'),
|
||||
(PangolinIcons.arrowUp, t.upload, '12.1', 'Mb/s'),
|
||||
(PangolinIcons.arrowDown, t.download, down, 'Mb/s'),
|
||||
(PangolinIcons.arrowUp, t.upload, up, 'Mb/s'),
|
||||
(PangolinIcons.zap, t.latency, node.ping > 0 ? '${node.ping}' : '—', 'ms'),
|
||||
];
|
||||
return Row(children: [
|
||||
|
||||
Reference in New Issue
Block a user