3aeb2a8680
- AppLang enum 扩为 zh/en/ja/ko/ru/es;新增 strings_{ja,ko,ru,es}.dart
(各 161 条,照 strings_en.dart 结构逐条翻译,无红线词,scan-redline 过)
- app_providers: localeProvider 默认 AppLang.en(国际化默认);appTextProvider
三元改 switch 全覆盖 6 语
- AppLang.nativeLabel 扩展(各语言本地名);settings/account 两处 _LangSwitch
段控改下拉(6 语横排会挤)
- flutter analyze lib 仅剩 2 个既有 withOpacity deprecation info
注:节点/套餐名、错误消息等 ~11 处数据驱动的 zh/en 三元暂回退 en(非崩溃,
后续可扩多语字段)。localeProvider 暂无持久化(沿用原设计,后续可加)。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
185 lines
7.2 KiB
Dart
185 lines
7.2 KiB
Dart
// settings_page.dart — 设置(desktop 一级页)
|
|
//
|
|
// 对照 ui_kits/desktop/dapp.jsx DSettings(精简):兑换入口 + 语言段控 +
|
|
// 深色外观 + 协议 + 版本。开关组(开机自启/智能分流/Kill-switch)待 l10n 补齐后加。
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../l10n/app_text.dart';
|
|
import '../pangolin_theme.dart';
|
|
import '../services/web_launch.dart';
|
|
import '../state/app_providers.dart';
|
|
import '../state/settings_provider.dart';
|
|
import '../state/update_provider.dart';
|
|
import '../widgets/pangolin_icons.dart';
|
|
import '../widgets/pangolin_toast.dart';
|
|
import '../widgets/update_dialog.dart';
|
|
|
|
/// 「检查更新」手动触发:拉取 `$kApiBaseUrl/version`,失败/无更新走轻提示,
|
|
/// 有更新则弹 [showUpdateDialog]。
|
|
Future<void> _checkForUpdate(BuildContext context, WidgetRef ref, AppText t) async {
|
|
final info = await ref.read(updateCheckerProvider).check();
|
|
if (!context.mounted) return;
|
|
if (info == null) {
|
|
showPangolinToast(context, t.updateCheckFailed);
|
|
return;
|
|
}
|
|
if (!info.hasUpdate) {
|
|
showPangolinToast(context, t.updateUpToDate);
|
|
return;
|
|
}
|
|
await showUpdateDialog(context, t, info);
|
|
}
|
|
|
|
class SettingsPage extends ConsumerWidget {
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final c = context.pangolin;
|
|
final t = ref.watch(appTextProvider);
|
|
final lang = ref.watch(localeProvider);
|
|
final mode = ref.watch(themeModeProvider);
|
|
final isDark = mode == ThemeMode.dark;
|
|
final s = ref.watch(settingsProvider);
|
|
final settings = ref.read(settingsProvider.notifier);
|
|
final version = ref.watch(appVersionProvider).valueOrNull ?? '…';
|
|
|
|
Widget sw(bool v, ValueChanged<bool> on) =>
|
|
Switch(value: v, activeThumbColor: c.accent, onChanged: on);
|
|
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.fromLTRB(32, 16, 32, 24),
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 560),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
// 兑换入口
|
|
_Card(children: [
|
|
_Row(title: t.redeemEntry, sub: t.proMember, last: true,
|
|
right: Icon(PangolinIcons.chevronRight, size: 18, color: c.fg3), onTap: () {}),
|
|
]),
|
|
const SizedBox(height: 16),
|
|
// 功能开关组(开机自启是桌面端登录项概念,iOS/Android 无此能力,仅桌面显示)
|
|
_Card(children: [
|
|
if (Platform.isMacOS || Platform.isWindows || Platform.isLinux)
|
|
_Row(title: t.autostart, sub: t.autostartSub, right: sw(s.autostart, settings.setAutostart)),
|
|
_Row(title: t.autoConnect, sub: t.autoConnectSub, right: sw(s.autoConnect, settings.setAutoConnect)),
|
|
_Row(title: t.smartRoute, sub: t.smartRouteSub, right: sw(s.smartRoute, settings.setSmartRoute)),
|
|
_Row(title: t.killSwitch, sub: t.killSwitchSub, last: true, right: sw(s.killSwitch, settings.setKillSwitch)),
|
|
]),
|
|
const SizedBox(height: 16),
|
|
// 配置组
|
|
_Card(children: [
|
|
_Row(title: t.language, right: _LangSwitch(lang: lang, onPick: (l) => ref.read(localeProvider.notifier).state = l)),
|
|
_Row(
|
|
title: t.darkAppearance,
|
|
sub: isDark ? t.stateOn : t.followLight,
|
|
right: sw(isDark, (v) => ref.read(themeModeProvider.notifier).state = v ? ThemeMode.dark : ThemeMode.light),
|
|
),
|
|
_Row(title: t.protocol, right: Text('REALITY / Hysteria2', style: PangolinText.mono.copyWith(fontSize: 13, color: c.fg3))),
|
|
_Row(title: t.webUserCenter, right: Icon(PangolinIcons.externalLink, size: 18, color: c.fg3), onTap: () => openWebUserCenter(ref)),
|
|
_Row(title: t.checkUpdate, right: Icon(PangolinIcons.chevronRight, size: 18, color: c.fg3), onTap: () => _checkForUpdate(context, ref, t)),
|
|
_Row(title: 'Version', last: true, right: Text(version, style: PangolinText.mono.copyWith(fontSize: 13, color: c.fg3))),
|
|
]),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Card extends StatelessWidget {
|
|
const _Card({required this.children});
|
|
final List<Widget> children;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final c = context.pangolin;
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: c.surface,
|
|
border: Border.all(color: c.border),
|
|
borderRadius: BorderRadius.circular(PangolinRadius.lg),
|
|
boxShadow: PangolinShadow.sm,
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(children: children),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Row extends StatelessWidget {
|
|
const _Row({required this.title, this.sub, required this.right, this.last = false, this.onTap});
|
|
final String title;
|
|
final String? sub;
|
|
final Widget right;
|
|
final bool last;
|
|
final VoidCallback? onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final c = context.pangolin;
|
|
return InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 14),
|
|
decoration: BoxDecoration(
|
|
border: last ? null : Border(bottom: BorderSide(color: c.border)),
|
|
),
|
|
child: Row(children: [
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(title, style: PangolinText.body.copyWith(color: c.fg1, fontSize: 14, fontWeight: FontWeight.w500)),
|
|
if (sub != null) Text(sub!, style: PangolinText.caption.copyWith(color: c.fg3)),
|
|
]),
|
|
),
|
|
right,
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LangSwitch extends StatelessWidget {
|
|
const _LangSwitch({required this.lang, required this.onPick});
|
|
final AppLang lang;
|
|
final ValueChanged<AppLang> onPick;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final c = context.pangolin;
|
|
// 6 种语言用下拉(段控横排会挤)。当前语言以本地名 + 下拉箭头展示。
|
|
return PopupMenuButton<AppLang>(
|
|
initialValue: lang,
|
|
onSelected: onPick,
|
|
color: c.surface,
|
|
elevation: 8,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(PangolinRadius.md)),
|
|
itemBuilder: (_) => [
|
|
for (final l in AppLang.values)
|
|
PopupMenuItem<AppLang>(
|
|
value: l,
|
|
height: 42,
|
|
child: Text(l.nativeLabel,
|
|
style: PangolinText.caption.copyWith(
|
|
color: l == lang ? c.accent : c.fg1,
|
|
fontWeight: l == lang ? FontWeight.w700 : FontWeight.w500,
|
|
fontSize: 13)),
|
|
),
|
|
],
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration:
|
|
BoxDecoration(color: c.bgSubtle, borderRadius: BorderRadius.circular(PangolinRadius.full)),
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
Text(lang.nativeLabel,
|
|
style: PangolinText.caption
|
|
.copyWith(color: c.fg2, fontWeight: FontWeight.w700, fontSize: 12)),
|
|
const SizedBox(width: 4),
|
|
Icon(PangolinIcons.chevronDown, size: 14, color: c.fg3),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|