f97ae8186b
对照 design/ui_kits mobile+tablet 原型逐屏补齐 Flutter 客户端: - l10n 资源层(strings_zh/en,单显)+ Riverpod 状态层(连接状态机/免费额度/ 节点选择/语言/主题),UI 与数据解耦,mock 数据接 API 不动 UI。 - 连接键严格三态(off 虚线轨道环 / connecting 旋转弧 / on 满环+计时+光晕), 状态来自 connectionProvider,点击只派发事件——禁止乐观显示。 - 节点页置顶「智能选择」推荐卡(clay 渐变 zap + 推荐胶囊,默认选中); 免费额度卡(剩余分钟+进度条 ≤3 分钟切 warning + 看广告解锁变绿)。 - Tab 左右滑动切换(手势竞技场仲裁,子页滚动不误触发,200ms 方向感知滑入)。 - iPad/宽屏 ≥900 LayoutBuilder 切侧栏分栏(导航行高 ≥48,连接页双栏/节点双列网格), 复用同一批原子组件,不 fork 页面。 - 语义 token 零硬编码;文案全部走 l10n;套餐数字对齐 §7;无支付表单/emoji 国旗。 - CI 红线词扫描扩展到 client/lib;新增 Flutter analyze+test CI 任务。 - 测试:连接状态机/额度/节点单测、连接键三态与卡片组件测试、 golden(连接键三态/推荐卡/额度卡 × 明暗)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
232 lines
8.0 KiB
Dart
232 lines
8.0 KiB
Dart
// connect_page.dart — 连接页(窄屏单栏 / 宽屏双栏,同一份代码按断点切换)
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../l10n/app_text.dart';
|
|
import '../models/node.dart';
|
|
import '../pangolin_theme.dart';
|
|
import '../state/app_providers.dart';
|
|
import '../state/connection_provider.dart';
|
|
import '../state/nodes_provider.dart';
|
|
import '../state/quota_provider.dart';
|
|
import '../widgets/app_top_bar.dart';
|
|
import '../widgets/connect_button.dart';
|
|
import '../widgets/country_code.dart';
|
|
import '../widgets/pangolin_icons.dart';
|
|
import '../widgets/quota_card.dart';
|
|
|
|
class ConnectPage extends ConsumerWidget {
|
|
const ConnectPage({super.key, required this.isWide, required this.onOpenNodes});
|
|
|
|
final bool isWide;
|
|
final VoidCallback onOpenNodes;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final c = context.pangolin;
|
|
final t = ref.watch(appTextProvider);
|
|
final conn = ref.watch(connectionProvider);
|
|
final node = ref.watch(effectiveNodeProvider);
|
|
final smart = ref.watch(isSmartSelectProvider);
|
|
final isFree = ref.watch(isFreePlanProvider);
|
|
final quota = ref.watch(quotaProvider);
|
|
|
|
final caption = switch (conn.phase) {
|
|
VpnPhase.off => t.capOff,
|
|
VpnPhase.connecting => t.capConnecting,
|
|
VpnPhase.on => t.capOn,
|
|
};
|
|
|
|
final button = ConnectButton(
|
|
phase: conn.phase,
|
|
elapsed: conn.elapsed,
|
|
offLabel: t.connectNow,
|
|
secureLabel: t.secure,
|
|
onTap: () => ref.read(connectionProvider.notifier).toggle(),
|
|
);
|
|
|
|
final captionWidget = Text(caption,
|
|
style: PangolinText.body.copyWith(color: c.fg2, fontWeight: FontWeight.w600));
|
|
|
|
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),
|
|
_CurrentNodeCard(t: t, node: node, smart: smart, showLabel: isWide, onTap: onOpenNodes),
|
|
];
|
|
|
|
final statusTrailing = Text(
|
|
conn.phase == VpnPhase.on ? t.online : t.offline,
|
|
style: PangolinText.mono.copyWith(
|
|
fontSize: 12,
|
|
color: conn.phase == VpnPhase.on ? c.success : c.fg3,
|
|
fontWeight: FontWeight.w600),
|
|
);
|
|
|
|
if (isWide) {
|
|
// 宽屏双栏:左大连接键 / 右信息列(额度卡→当前节点→速率)
|
|
return Column(children: [
|
|
Expanded(
|
|
child: Row(children: [
|
|
Expanded(
|
|
flex: 5,
|
|
child: Center(
|
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
button,
|
|
const SizedBox(height: 24),
|
|
captionWidget,
|
|
]),
|
|
),
|
|
),
|
|
Container(width: 1, color: c.border),
|
|
SizedBox(
|
|
width: 332,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
for (final w in infoChildren) Padding(padding: const EdgeInsets.only(bottom: 14), child: w),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
]);
|
|
}
|
|
|
|
// 窄屏单栏
|
|
return Column(children: [
|
|
AppTopBar(brand: t.brand, trailing: statusTrailing),
|
|
Expanded(
|
|
child: Center(
|
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
button,
|
|
const SizedBox(height: 24),
|
|
captionWidget,
|
|
]),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 18),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
for (final w in infoChildren) Padding(padding: const EdgeInsets.only(bottom: 12), child: w),
|
|
]),
|
|
),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/// 实时速率行(连接成功时显示;演示值)。
|
|
class _SpeedRow extends StatelessWidget {
|
|
const _SpeedRow({required this.t, required this.node});
|
|
final AppText t;
|
|
final Node node;
|
|
|
|
@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.zap, t.latency, '${node.ping}', 'ms'),
|
|
];
|
|
return Row(children: [
|
|
for (var i = 0; i < metrics.length; i++)
|
|
Expanded(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(right: i < metrics.length - 1 ? 12 : 0),
|
|
child: Container(
|
|
padding: const EdgeInsets.fromLTRB(13, 11, 13, 11),
|
|
decoration: BoxDecoration(
|
|
color: c.surface,
|
|
borderRadius: BorderRadius.circular(PangolinRadius.lg),
|
|
border: Border.all(color: c.border),
|
|
boxShadow: PangolinShadow.sm,
|
|
),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(children: [
|
|
Icon(metrics[i].$1, size: 13, color: c.accent),
|
|
const SizedBox(width: 5),
|
|
Flexible(
|
|
child: Text(metrics[i].$2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w600, fontSize: 11)),
|
|
),
|
|
]),
|
|
const SizedBox(height: 4),
|
|
Text.rich(TextSpan(
|
|
text: metrics[i].$3,
|
|
style: PangolinText.mono.copyWith(fontSize: 16, color: c.fg1, fontWeight: FontWeight.w500),
|
|
children: [TextSpan(text: ' ${metrics[i].$4}', style: PangolinText.caption.copyWith(color: c.fg3, fontSize: 10.5))],
|
|
)),
|
|
]),
|
|
),
|
|
),
|
|
),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/// 当前节点卡(智能选择时展示「智能选择 + zap」)。
|
|
class _CurrentNodeCard extends StatelessWidget {
|
|
const _CurrentNodeCard({
|
|
required this.t,
|
|
required this.node,
|
|
required this.smart,
|
|
required this.showLabel,
|
|
required this.onTap,
|
|
});
|
|
final AppText t;
|
|
final Node node;
|
|
final bool smart;
|
|
final bool showLabel;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final c = context.pangolin;
|
|
final title = smart ? t.smartSelect : node.localizedName(t.lang);
|
|
final sub = smart
|
|
? '${node.localizedName(t.lang)} · ${node.ping}ms'
|
|
: '${node.localizedSub(t.lang)} · ${node.ping}ms';
|
|
return Material(
|
|
color: c.surface,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(PangolinRadius.lg),
|
|
side: BorderSide(color: c.border),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Row(children: [
|
|
CountryCode(code: node.code, active: true),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
if (showLabel)
|
|
Text(t.currentNode,
|
|
style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w600, fontSize: 11)),
|
|
Row(children: [
|
|
Flexible(
|
|
child: Text(title,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: PangolinText.body.copyWith(color: c.fg1, fontWeight: FontWeight.w600)),
|
|
),
|
|
if (smart) ...[const SizedBox(width: 6), Icon(PangolinIcons.zap, size: 13, color: c.accent)],
|
|
]),
|
|
Text(sub, style: PangolinText.caption.copyWith(color: c.fg3, fontWeight: FontWeight.w400)),
|
|
]),
|
|
),
|
|
Icon(PangolinIcons.chevronRight, size: 20, color: c.fg3),
|
|
]),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|