2026-11-25 12:39:48 +08:00
|
|
|
|
// Settings, organised like the desktop client: a short index of categories,
|
|
|
|
|
|
// each opening its own page. 通用 holds the server-backed chat behavior, 外观
|
|
|
|
|
|
// the device-local theme and pet, 帮助与关于 the app itself.
|
2026-11-22 13:39:49 +08:00
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
2026-11-25 12:39:48 +08:00
|
|
|
|
import 'package:flutter/foundation.dart'
|
|
|
|
|
|
show LicenseEntry, LicenseParagraph, LicenseRegistry;
|
2026-11-21 19:17:22 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
import '../api/models.dart';
|
2026-11-26 09:04:25 +08:00
|
|
|
|
import '../l10n.dart';
|
2026-11-21 19:17:22 +08:00
|
|
|
|
import '../appearance_prefs.dart';
|
2026-11-22 13:39:49 +08:00
|
|
|
|
import '../pets/pet_library.dart';
|
2026-11-25 12:39:48 +08:00
|
|
|
|
import '../pets/pet_pack.dart';
|
2026-11-21 19:17:22 +08:00
|
|
|
|
import '../state.dart';
|
2026-11-25 12:39:48 +08:00
|
|
|
|
import '../version.dart';
|
2026-11-21 19:17:22 +08:00
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
class SettingsScreen extends StatelessWidget {
|
2026-11-21 19:17:22 +08:00
|
|
|
|
final AppState app;
|
|
|
|
|
|
const SettingsScreen({super.key, required this.app});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2026-11-25 12:39:48 +08:00
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('设置')),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
body: ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
|
|
|
|
|
children: [
|
2026-11-25 14:30:29 +08:00
|
|
|
|
const _SectionHeader('常规'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
_Section(children: [
|
2026-11-26 09:04:25 +08:00
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.translate,
|
|
|
|
|
|
title: '语言',
|
|
|
|
|
|
subtitle: '跟随系统、中文或 English',
|
|
|
|
|
|
builder: (_) => const LanguageSettingsPage(),
|
|
|
|
|
|
),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.tune,
|
|
|
|
|
|
title: '通用',
|
|
|
|
|
|
subtitle: '智能体工具与记忆',
|
|
|
|
|
|
builder: (_) => GeneralSettingsPage(app: app),
|
|
|
|
|
|
),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.chat_bubble_outline,
|
|
|
|
|
|
title: '聊天',
|
|
|
|
|
|
subtitle: '追问处理行为',
|
|
|
|
|
|
builder: (_) => ChatSettingsPage(app: app),
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
const _SectionHeader('外观', note: '仅当前设备生效,不同步到服务器'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.palette_outlined,
|
|
|
|
|
|
title: '主题',
|
|
|
|
|
|
subtitle: '主题模式与主题色',
|
|
|
|
|
|
builder: (_) => const ThemeSettingsPage(),
|
|
|
|
|
|
),
|
|
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.pets_outlined,
|
|
|
|
|
|
title: '宠物',
|
|
|
|
|
|
subtitle: '导入、启用与大小',
|
|
|
|
|
|
builder: (_) => const PetSettingsPage(),
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
const _SectionHeader('帮助与关于'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
_NavTile(
|
|
|
|
|
|
icon: Icons.info_outline,
|
|
|
|
|
|
title: '关于',
|
|
|
|
|
|
subtitle: '版本、服务端与开源许可',
|
|
|
|
|
|
builder: (_) => AboutSettingsPage(app: app),
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-11-21 19:17:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-25 14:30:29 +08:00
|
|
|
|
// ---------------------------------------------------------------- general
|
|
|
|
|
|
|
|
|
|
|
|
/// OpenChamber's own agent tools: what the agent may do inside a chat, and
|
|
|
|
|
|
/// what it may know about the person and the project. The web client keeps
|
|
|
|
|
|
/// these on its 通用 page; the keys and wording follow it.
|
|
|
|
|
|
class GeneralSettingsPage extends StatefulWidget {
|
|
|
|
|
|
final AppState app;
|
|
|
|
|
|
const GeneralSettingsPage({super.key, required this.app});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<GeneralSettingsPage> createState() => _GeneralSettingsPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _GeneralSettingsPageState extends State<GeneralSettingsPage> {
|
|
|
|
|
|
/// Image models the provider offers, for the 图像模型 row. Null until the
|
|
|
|
|
|
/// first load; empty means the provider has none.
|
|
|
|
|
|
List<ModelInfo>? _imageModels;
|
|
|
|
|
|
|
|
|
|
|
|
AppState get app => widget.app;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
app.refreshChatSettings();
|
|
|
|
|
|
if (app.modelList.isEmpty) app.refreshModels();
|
|
|
|
|
|
_loadImageModels();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _loadImageModels() async {
|
|
|
|
|
|
final client = app.client;
|
|
|
|
|
|
if (client == null) return;
|
|
|
|
|
|
try {
|
|
|
|
|
|
final models = await client.imageModels(app.directory);
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
setState(() => _imageModels = models);
|
|
|
|
|
|
} catch (_) {
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
setState(() => _imageModels = const []);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _save(String key, Object value) async {
|
|
|
|
|
|
final ok = await app.setAgentToolSetting(key, value);
|
|
|
|
|
|
if (!ok && mounted) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
SnackBar(
|
|
|
|
|
|
content: AppText(
|
|
|
|
|
|
trArgs('保存失败:{0}', [app.lastError ?? tr('未知错误')]))),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
);
|
|
|
|
|
|
app.clearLastError();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('通用')),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
body: ListenableBuilder(
|
|
|
|
|
|
listenable: app,
|
|
|
|
|
|
builder: (context, _) => ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const _SectionHeader('在聊天中'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.bar_chart,
|
|
|
|
|
|
title: '图表和原型',
|
|
|
|
|
|
subtitle: '让智能体在聊天中展示图表、表格、示意图和界面草图(与你的文件隔离),并请你在其中选择一个选项。',
|
|
|
|
|
|
value: app.renderToolEnabled,
|
|
|
|
|
|
key: 'agentRenderToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.image_outlined,
|
|
|
|
|
|
title: '图像',
|
|
|
|
|
|
subtitle: '让智能体用你选择的模型生成和编辑图像,费用由该模型的提供商收取。',
|
|
|
|
|
|
value: app.imageToolEnabled,
|
|
|
|
|
|
key: 'agentImageToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
if (app.imageToolEnabled)
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
contentPadding: const EdgeInsets.fromLTRB(52, 0, 16, 4),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('图像模型'),
|
|
|
|
|
|
subtitle: AppText(_imageModelName(),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
maxLines: 1, overflow: TextOverflow.ellipsis),
|
|
|
|
|
|
trailing: const Icon(Icons.chevron_right, size: 20),
|
|
|
|
|
|
onTap: _pickImageModel,
|
|
|
|
|
|
),
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.shield_outlined,
|
|
|
|
|
|
title: '密钥',
|
|
|
|
|
|
subtitle: '允许智能体在聊天中的私密卡片上向你索取 API 密钥、令牌或密码。值不会进入对话。',
|
|
|
|
|
|
value: app.secretToolEnabled,
|
|
|
|
|
|
key: 'agentSecretToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.notifications_none,
|
|
|
|
|
|
title: '通知',
|
|
|
|
|
|
subtitle: '工作完成或卡住时,智能体会通知你。',
|
|
|
|
|
|
value: app.notifyToolEnabled,
|
|
|
|
|
|
key: 'agentNotifyToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
const _SectionHeader('智能体知道的内容'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
if (app.memoryToolsAvailable) ...[
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.psychology_outlined,
|
|
|
|
|
|
title: '记忆',
|
|
|
|
|
|
subtitle: '跨会话记住关于你和每个项目的事实。',
|
|
|
|
|
|
value: app.memoryToolEnabled,
|
|
|
|
|
|
key: 'agentMemoryToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
if (app.memoryToolEnabled) ..._dreaming(theme),
|
|
|
|
|
|
],
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.sticky_note_2_outlined,
|
|
|
|
|
|
title: '项目知识',
|
|
|
|
|
|
subtitle: '让智能体读取并更新项目的笔记、待办和计划。',
|
|
|
|
|
|
value: app.knowledgeToolEnabled,
|
|
|
|
|
|
key: 'agentKnowledgeToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
_switch(
|
|
|
|
|
|
icon: Icons.insert_chart_outlined,
|
|
|
|
|
|
title: '用量限额',
|
|
|
|
|
|
subtitle: '让智能体查看各提供商的限额及重置时间。',
|
|
|
|
|
|
value: app.usageToolEnabled,
|
|
|
|
|
|
key: 'agentUsageToolEnabled',
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _switch({
|
|
|
|
|
|
required IconData icon,
|
|
|
|
|
|
required String title,
|
|
|
|
|
|
required String subtitle,
|
|
|
|
|
|
required bool value,
|
|
|
|
|
|
required String key,
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return SwitchListTile(
|
|
|
|
|
|
value: value,
|
|
|
|
|
|
onChanged: (v) => _save(key, v),
|
|
|
|
|
|
secondary: Icon(icon, size: 20),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(title),
|
|
|
|
|
|
subtitle: AppText(subtitle),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String _imageModelName() {
|
|
|
|
|
|
final value = app.imageModel;
|
|
|
|
|
|
if (value.isEmpty) return '未选择';
|
|
|
|
|
|
for (final m in _imageModels ?? const <ModelInfo>[]) {
|
|
|
|
|
|
if ('${m.providerId}/${m.id}' == value) return m.name;
|
|
|
|
|
|
}
|
|
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The memory-tidying switch with its model and thinking level, shown under
|
|
|
|
|
|
/// 记忆 the way the web client draws it.
|
|
|
|
|
|
List<Widget> _dreaming(ThemeData theme) {
|
|
|
|
|
|
final variants = _dreamingVariants();
|
|
|
|
|
|
final name = app.memoryDreamingModel.isEmpty
|
|
|
|
|
|
? '默认模型'
|
|
|
|
|
|
: (app.modelNames[app.memoryDreamingModel] ?? app.memoryDreamingModel);
|
|
|
|
|
|
return [
|
|
|
|
|
|
InkWell(
|
|
|
|
|
|
onTap: () =>
|
|
|
|
|
|
_save('agentMemoryDreamingEnabled', !app.memoryDreamingEnabled),
|
|
|
|
|
|
child: Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(44, 0, 4, 0),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Checkbox(
|
|
|
|
|
|
value: app.memoryDreamingEnabled,
|
|
|
|
|
|
onChanged: (v) =>
|
|
|
|
|
|
_save('agentMemoryDreamingEnabled', v ?? false),
|
|
|
|
|
|
),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
Expanded(child: AppText('整理记忆')),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
IconButton(
|
|
|
|
|
|
icon: const Icon(Icons.info_outline, size: 18),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
tooltip: tr('整理记忆'),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
onPressed: _dreamingInfo,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
if (app.memoryDreamingEnabled)
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(56, 0, 16, 10),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: OutlinedButton(
|
|
|
|
|
|
onPressed: _pickDreamingModel,
|
|
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
|
|
),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(name,
|
2026-11-25 14:30:29 +08:00
|
|
|
|
maxLines: 1,
|
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
|
style: const TextStyle(fontSize: 13)),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
if (variants.isNotEmpty) ...[
|
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
|
DropdownButton<String>(
|
|
|
|
|
|
value: variants.contains(app.memoryDreamingVariant)
|
|
|
|
|
|
? app.memoryDreamingVariant
|
|
|
|
|
|
: '',
|
|
|
|
|
|
underline: const SizedBox.shrink(),
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 13, color: theme.colorScheme.onSurface),
|
|
|
|
|
|
items: [
|
2026-11-26 09:04:25 +08:00
|
|
|
|
const DropdownMenuItem(value: '', child: AppText('默认')),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
for (final v in variants)
|
2026-11-26 09:04:25 +08:00
|
|
|
|
DropdownMenuItem(value: v, child: AppText(v)),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
],
|
|
|
|
|
|
onChanged: (v) => _save('agentMemoryDreamingVariant', v ?? ''),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> _dreamingVariants() {
|
|
|
|
|
|
for (final m in app.modelList) {
|
|
|
|
|
|
if ('${m.providerId}/${m.id}' == app.memoryDreamingModel) {
|
|
|
|
|
|
return m.variants;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return const [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _dreamingInfo() async {
|
|
|
|
|
|
await showDialog<void>(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
builder: (dialog) => AlertDialog(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('整理记忆'),
|
|
|
|
|
|
content: const AppText(
|
2026-11-25 14:30:29 +08:00
|
|
|
|
'每天一次,在没有会话运行时,智能体会在后台整理记忆:合并重复条目,删除已过时或项目文档中已有的内容。'),
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
onPressed: () => Navigator.pop(dialog), child: const AppText('知道了')),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _pickImageModel() async {
|
|
|
|
|
|
final models = _imageModels ??= await _fetchImageModels();
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
if (models.isEmpty) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
const SnackBar(content: AppText('你的提供商中没有图像模型')),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
final picked = await _chooseFromSheet(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
title: '图像模型',
|
|
|
|
|
|
noneLabel: '不指定',
|
|
|
|
|
|
selected: app.imageModel,
|
|
|
|
|
|
options: [
|
|
|
|
|
|
for (final m in models)
|
|
|
|
|
|
(value: '${m.providerId}/${m.id}', name: m.name, note: m.providerId),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
if (picked == null) return;
|
|
|
|
|
|
await _save('agentImageModel', picked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<List<ModelInfo>> _fetchImageModels() async {
|
|
|
|
|
|
final client = app.client;
|
|
|
|
|
|
if (client == null) return const [];
|
|
|
|
|
|
try {
|
|
|
|
|
|
return await client.imageModels(app.directory);
|
|
|
|
|
|
} catch (_) {
|
|
|
|
|
|
return const [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _pickDreamingModel() async {
|
|
|
|
|
|
if (app.modelList.isEmpty) await app.refreshModels();
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
final picked = await _chooseFromSheet(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
title: '整理记忆使用的模型',
|
|
|
|
|
|
noneLabel: '默认模型',
|
|
|
|
|
|
selected: app.memoryDreamingModel,
|
|
|
|
|
|
options: [
|
|
|
|
|
|
for (final m in app.modelList)
|
|
|
|
|
|
(value: '${m.providerId}/${m.id}', name: m.name, note: m.providerId),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
if (picked == null) return;
|
|
|
|
|
|
// A model change drops the thinking level: the new model may not offer
|
|
|
|
|
|
// the old one.
|
|
|
|
|
|
await _save('agentMemoryDreamingModel', picked);
|
|
|
|
|
|
if (app.memoryDreamingVariant.isNotEmpty) {
|
|
|
|
|
|
await _save('agentMemoryDreamingVariant', '');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A sheet of model choices; the first row clears the choice. Null when the
|
|
|
|
|
|
/// sheet is dismissed.
|
|
|
|
|
|
Future<String?> _chooseFromSheet({
|
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
|
required String title,
|
|
|
|
|
|
required String noneLabel,
|
|
|
|
|
|
required String selected,
|
|
|
|
|
|
required List<({String value, String name, String note})> options,
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return showModalBottomSheet<String>(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
|
showDragHandle: true,
|
|
|
|
|
|
builder: (sheet) => FractionallySizedBox(
|
|
|
|
|
|
heightFactor: 0.65,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(title,
|
2026-11-25 14:30:29 +08:00
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontSize: 16, fontWeight: FontWeight.w600)),
|
|
|
|
|
|
),
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 24),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(noneLabel),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
trailing: selected.isEmpty
|
|
|
|
|
|
? const Icon(Icons.check, size: 20)
|
|
|
|
|
|
: null,
|
|
|
|
|
|
onTap: () => Navigator.pop(sheet, ''),
|
|
|
|
|
|
),
|
|
|
|
|
|
for (final option in options)
|
|
|
|
|
|
ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(option.name,
|
2026-11-25 14:30:29 +08:00
|
|
|
|
maxLines: 1, overflow: TextOverflow.ellipsis),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
subtitle: option.note.isEmpty ? null : AppText(option.note),
|
2026-11-25 14:30:29 +08:00
|
|
|
|
trailing: selected == option.value
|
|
|
|
|
|
? const Icon(Icons.check, size: 20)
|
|
|
|
|
|
: null,
|
|
|
|
|
|
onTap: () => Navigator.pop(sheet, option.value),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-26 09:04:25 +08:00
|
|
|
|
// --------------------------------------------------------------- language
|
|
|
|
|
|
|
|
|
|
|
|
/// The UI language: follow the system, or pin Chinese or English.
|
|
|
|
|
|
class LanguageSettingsPage extends StatelessWidget {
|
|
|
|
|
|
const LanguageSettingsPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final l10n = L10n.instance;
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
appBar: AppBar(title: const AppText('语言')),
|
|
|
|
|
|
body: ListenableBuilder(
|
|
|
|
|
|
listenable: l10n,
|
|
|
|
|
|
builder: (context, _) {
|
|
|
|
|
|
final english = l10n.isEnglish;
|
|
|
|
|
|
final systemName = l10n.locale.languageCode == 'zh'
|
|
|
|
|
|
? AppLanguage.zh.labelFor(english)
|
|
|
|
|
|
: AppLanguage.en.labelFor(english);
|
|
|
|
|
|
return ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
RadioGroup<AppLanguage>(
|
|
|
|
|
|
groupValue: l10n.choice,
|
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
|
if (value != null) l10n.setLanguage(value);
|
|
|
|
|
|
},
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
for (final choice in AppLanguage.values)
|
|
|
|
|
|
RadioListTile<AppLanguage>(
|
|
|
|
|
|
value: choice,
|
|
|
|
|
|
title: AppText(choice.labelFor(english)),
|
|
|
|
|
|
subtitle: choice == AppLanguage.system
|
|
|
|
|
|
? AppText(trArgs('当前:{0}', [systemName]))
|
|
|
|
|
|
: null,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
|
|
|
|
|
child: AppText(
|
|
|
|
|
|
'界面文字与系统自带的日期、时间选择器会一起切换。',
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 12.5,
|
|
|
|
|
|
color: Theme.of(context).hintColor),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
// ------------------------------------------------------------------- chat
|
|
|
|
|
|
|
|
|
|
|
|
class ChatSettingsPage extends StatefulWidget {
|
|
|
|
|
|
final AppState app;
|
|
|
|
|
|
const ChatSettingsPage({super.key, required this.app});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<ChatSettingsPage> createState() => _ChatSettingsPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
2026-11-21 19:17:22 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
// Pick up a change made on another client while this page opens.
|
2026-11-25 14:30:29 +08:00
|
|
|
|
widget.app.refreshChatSettings();
|
2026-11-21 19:17:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2026-11-25 12:39:48 +08:00
|
|
|
|
final theme = Theme.of(context);
|
2026-11-21 19:17:22 +08:00
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('聊天')),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
body: ListenableBuilder(
|
2026-11-25 12:39:48 +08:00
|
|
|
|
listenable: widget.app,
|
2026-11-21 19:17:22 +08:00
|
|
|
|
builder: (context, _) {
|
2026-11-25 12:39:48 +08:00
|
|
|
|
final steer = widget.app.followUpBehavior == 'steer';
|
2026-11-21 19:17:22 +08:00
|
|
|
|
return ListView(
|
2026-11-25 12:39:48 +08:00
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
children: [
|
2026-11-25 12:39:48 +08:00
|
|
|
|
const ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText('追问处理行为'),
|
|
|
|
|
|
subtitle: AppText('运行中按发送时,消息默认怎么处理。与网页端设置同步。'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
|
|
|
|
|
child: Wrap(
|
|
|
|
|
|
spacing: 8,
|
|
|
|
|
|
runSpacing: 8,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
ChoiceChip(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: const AppText('转向'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
selected: steer,
|
|
|
|
|
|
onSelected: (_) => _setFollowUp('steer'),
|
|
|
|
|
|
),
|
|
|
|
|
|
ChoiceChip(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: const AppText('排队'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
selected: !steer,
|
|
|
|
|
|
onSelected: (_) => _setFollowUp('queue'),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(
|
2026-11-25 12:39:48 +08:00
|
|
|
|
steer ? '转向:在下一步加入当前回合,工作继续。' : '排队:等当前回合结束后再发送。',
|
|
|
|
|
|
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
Future<void> _setFollowUp(String value) async {
|
|
|
|
|
|
final ok = await widget.app.setFollowUpBehavior(value);
|
|
|
|
|
|
if (!ok && mounted) {
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
SnackBar(content: AppText(widget.app.lastError ?? '保存失败')),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
);
|
|
|
|
|
|
widget.app.clearLastError();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-21 19:17:22 +08:00
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
// ------------------------------------------------------------------ theme
|
|
|
|
|
|
|
|
|
|
|
|
class ThemeSettingsPage extends StatelessWidget {
|
|
|
|
|
|
const ThemeSettingsPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
static const _modes = [
|
|
|
|
|
|
(ThemeMode.system, '跟随系统'),
|
|
|
|
|
|
(ThemeMode.light, '浅色'),
|
|
|
|
|
|
(ThemeMode.dark, '深色'),
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final look = AppearancePrefs.instance;
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('主题')),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
body: ListenableBuilder(
|
|
|
|
|
|
listenable: look,
|
|
|
|
|
|
builder: (context, _) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
return ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
children: [
|
2026-11-25 12:39:48 +08:00
|
|
|
|
const Padding(
|
|
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText('主题只保存在本机,不随服务器同步。',
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: TextStyle(fontSize: 12.5)),
|
|
|
|
|
|
),
|
|
|
|
|
|
const _Label('主题模式'),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
|
|
|
|
|
|
child: Wrap(
|
|
|
|
|
|
spacing: 8,
|
|
|
|
|
|
runSpacing: 8,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
for (final (mode, label) in _modes)
|
|
|
|
|
|
ChoiceChip(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: AppText(label),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
selected: look.themeMode == mode,
|
|
|
|
|
|
onSelected: (_) => look.setThemeMode(mode),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-11-21 19:17:22 +08:00
|
|
|
|
),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
),
|
|
|
|
|
|
const _Label('主题色'),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
|
|
|
|
|
child: Wrap(
|
|
|
|
|
|
spacing: 12,
|
|
|
|
|
|
runSpacing: 12,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
for (final seed in appearanceSeeds)
|
|
|
|
|
|
_swatch(theme, look, seed),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
],
|
2026-11-25 12:39:48 +08:00
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _swatch(ThemeData theme, AppearancePrefs look, int seed) {
|
|
|
|
|
|
final color = Color(seed);
|
|
|
|
|
|
final selected = look.seedColor.toARGB32() == seed;
|
|
|
|
|
|
return Semantics(
|
|
|
|
|
|
button: true,
|
|
|
|
|
|
selected: selected,
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: trArgs('主题色 {0}', [seed.toRadixString(16)]),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
child: InkWell(
|
|
|
|
|
|
borderRadius: BorderRadius.circular(22),
|
|
|
|
|
|
onTap: () => look.setSeedColor(seed),
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
width: 40,
|
|
|
|
|
|
height: 40,
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: color,
|
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
|
border: Border.all(
|
|
|
|
|
|
color: selected
|
|
|
|
|
|
? theme.colorScheme.onSurface
|
|
|
|
|
|
: theme.colorScheme.outlineVariant,
|
|
|
|
|
|
width: selected ? 2.5 : 1,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: selected
|
|
|
|
|
|
? const Icon(Icons.check, size: 20, color: Colors.white)
|
|
|
|
|
|
: null,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-11-25 12:39:48 +08:00
|
|
|
|
}
|
2026-11-21 19:17:22 +08:00
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
// -------------------------------------------------------------------- pet
|
2026-11-21 19:17:22 +08:00
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
class PetSettingsPage extends StatefulWidget {
|
|
|
|
|
|
const PetSettingsPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<PetSettingsPage> createState() => _PetSettingsPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _PetSettingsPageState extends State<PetSettingsPage> {
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
PetLibrary.instance.ensureLoaded();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('宠物')),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
body: ListenableBuilder(
|
|
|
|
|
|
listenable: PetLibrary.instance,
|
|
|
|
|
|
builder: (context, _) {
|
|
|
|
|
|
final library = PetLibrary.instance;
|
|
|
|
|
|
final pack = library.pack;
|
|
|
|
|
|
return ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const Padding(
|
|
|
|
|
|
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText('默认不提供宠物;宠物包只存放在本机。',
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: TextStyle(fontSize: 12.5)),
|
|
|
|
|
|
),
|
|
|
|
|
|
if (pack == null) ..._empty(theme) else ..._loaded(theme, pack),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Widget> _empty(ThemeData theme) => [
|
2026-11-21 19:17:22 +08:00
|
|
|
|
const ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText('尚未导入宠物'),
|
|
|
|
|
|
subtitle: AppText('导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
child: FilledButton.tonalIcon(
|
|
|
|
|
|
onPressed: _importPet,
|
|
|
|
|
|
icon: const Icon(Icons.file_upload_outlined, size: 18),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: const AppText('导入宠物包'),
|
2026-11-21 19:17:22 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
];
|
2026-11-21 19:17:22 +08:00
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
List<Widget> _loaded(ThemeData theme, PetPack pack) {
|
2026-11-22 13:39:49 +08:00
|
|
|
|
final library = PetLibrary.instance;
|
2026-11-25 12:39:48 +08:00
|
|
|
|
final info =
|
|
|
|
|
|
[pack.author, pack.license].where((s) => s.trim().isNotEmpty).join(' · ');
|
|
|
|
|
|
return [
|
|
|
|
|
|
ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(pack.name.isEmpty ? pack.id : pack.name),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
subtitle: info.isEmpty
|
|
|
|
|
|
? null
|
2026-11-26 09:04:25 +08:00
|
|
|
|
: AppText(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
),
|
|
|
|
|
|
SwitchListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('启用宠物'),
|
|
|
|
|
|
subtitle: const AppText('站在输入框上方,默认关闭'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
value: library.enabled,
|
|
|
|
|
|
onChanged: (v) => library.setEnabled(v),
|
|
|
|
|
|
),
|
|
|
|
|
|
const _Label('大小'),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
|
|
|
|
|
child: Wrap(
|
|
|
|
|
|
spacing: 8,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
for (final (size, label) in const [
|
|
|
|
|
|
(40.0, '小'),
|
|
|
|
|
|
(52.0, '中'),
|
|
|
|
|
|
(64.0, '大'),
|
|
|
|
|
|
])
|
|
|
|
|
|
ChoiceChip(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: AppText(label),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
selected: (library.size - size).abs() < 0.5,
|
|
|
|
|
|
onSelected: (_) => library.setSize(size),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 2, 20, 8),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
FilledButton.tonalIcon(
|
2026-11-22 13:39:49 +08:00
|
|
|
|
onPressed: _importPet,
|
2026-11-25 12:39:48 +08:00
|
|
|
|
icon: const Icon(Icons.swap_horiz, size: 18),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
label: const AppText('更换宠物包'),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
onPressed: _confirmRemovePet,
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: const AppText('移除'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
2026-11-22 13:39:49 +08:00
|
|
|
|
),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
),
|
|
|
|
|
|
];
|
2026-11-22 13:39:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _importPet() async {
|
|
|
|
|
|
try {
|
|
|
|
|
|
final file = await FilePicker.pickFile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
dialogTitle: tr('选择宠物包(.zip)'),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
type: FileType.custom,
|
|
|
|
|
|
allowedExtensions: const ['zip'],
|
|
|
|
|
|
);
|
|
|
|
|
|
if (file == null) return;
|
|
|
|
|
|
final bytes = await file.readAsBytes();
|
|
|
|
|
|
final pack = await PetLibrary.instance.importZip(bytes);
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
SnackBar(
|
|
|
|
|
|
content: AppText(trArgs(
|
|
|
|
|
|
'已导入 {0}', [pack.name.isEmpty ? pack.id : pack.name]))),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
SnackBar(content: AppText(trArgs('导入失败:{0}', [e]))),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _confirmRemovePet() async {
|
|
|
|
|
|
final ok = await showDialog<bool>(
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
builder: (dialog) => AlertDialog(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('移除宠物?'),
|
|
|
|
|
|
content: const AppText('本机保存的宠物包会被删除。'),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
onPressed: () => Navigator.pop(dialog, false),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: const AppText('取消')),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
FilledButton(
|
|
|
|
|
|
onPressed: () => Navigator.pop(dialog, true),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: const AppText('移除')),
|
2026-11-22 13:39:49 +08:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (ok == true) await PetLibrary.instance.remove();
|
|
|
|
|
|
}
|
2026-11-21 19:17:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-25 12:39:48 +08:00
|
|
|
|
// ------------------------------------------------------------------ about
|
|
|
|
|
|
|
|
|
|
|
|
class AboutSettingsPage extends StatefulWidget {
|
|
|
|
|
|
final AppState app;
|
|
|
|
|
|
const AboutSettingsPage({super.key, required this.app});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<AboutSettingsPage> createState() => _AboutSettingsPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
|
|
|
|
|
ServerVersions? _versions;
|
|
|
|
|
|
bool _loading = false;
|
|
|
|
|
|
bool _loaded = false;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
_load();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _load() async {
|
|
|
|
|
|
final client = widget.app.client;
|
|
|
|
|
|
if (client == null) {
|
|
|
|
|
|
setState(() => _loaded = true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
setState(() => _loading = true);
|
|
|
|
|
|
final versions = await client.serverVersions();
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_versions = versions;
|
|
|
|
|
|
_loading = false;
|
|
|
|
|
|
_loaded = true;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// What a version row shows: a spinner while fetching, then the value, or
|
|
|
|
|
|
/// why there is none.
|
|
|
|
|
|
Widget _version(BuildContext context, String value) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
if (_loading) {
|
|
|
|
|
|
return const SizedBox(
|
|
|
|
|
|
width: 14, height: 14, child: CircularProgressIndicator(strokeWidth: 1.6));
|
|
|
|
|
|
}
|
|
|
|
|
|
final text = !_loaded
|
|
|
|
|
|
? '读取中…'
|
|
|
|
|
|
: widget.app.client == null
|
|
|
|
|
|
? '未连接'
|
|
|
|
|
|
: value.isEmpty
|
|
|
|
|
|
? '未获取到'
|
|
|
|
|
|
: value;
|
2026-11-26 09:04:25 +08:00
|
|
|
|
return AppText(text,
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
|
color: text == value && value.isNotEmpty
|
|
|
|
|
|
? theme.colorScheme.onSurface
|
|
|
|
|
|
: theme.hintColor));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
final versions = _versions;
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
appBar: AppBar(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('关于'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
actions: [
|
|
|
|
|
|
IconButton(
|
|
|
|
|
|
icon: const Icon(Icons.refresh),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
tooltip: tr('重新获取服务端版本'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
onPressed: _loading ? null : _load,
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
body: ListView(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 16, 20, 10),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Container(
|
|
|
|
|
|
width: 52,
|
|
|
|
|
|
height: 52,
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
color: theme.colorScheme.primaryContainer,
|
|
|
|
|
|
borderRadius: BorderRadius.circular(14),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Icon(Icons.forum_rounded,
|
|
|
|
|
|
size: 28, color: theme.colorScheme.onPrimaryContainer),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(width: 14),
|
|
|
|
|
|
Expanded(
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
2026-11-26 09:04:25 +08:00
|
|
|
|
AppText('OpenChamber',
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: theme.textTheme.titleLarge
|
|
|
|
|
|
?.copyWith(fontWeight: FontWeight.w600)),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
AppText('手机客户端',
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 12.5, color: theme.hintColor)),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const _SectionHeader('应用'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.tag, size: 20),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('版本'),
|
|
|
|
|
|
trailing: AppText(
|
2026-11-25 12:39:48 +08:00
|
|
|
|
appVersion.isEmpty ? '未知' : appVersion,
|
|
|
|
|
|
style: const TextStyle(fontSize: 13),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.description_outlined, size: 20),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('开源许可'),
|
|
|
|
|
|
subtitle: const AppText('本应用使用的第三方组件与它们的许可证'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
trailing: const Icon(Icons.chevron_right, size: 20),
|
|
|
|
|
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
|
builder: (_) => const LicensesPage(),
|
|
|
|
|
|
)),
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
const _SectionHeader('服务端', note: '版本取自当前连接的服务器'),
|
|
|
|
|
|
_Section(children: [
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.terminal, size: 20),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('OpenCode'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
trailing: _version(context, versions?.opencode ?? ''),
|
|
|
|
|
|
),
|
|
|
|
|
|
ListTile(
|
|
|
|
|
|
leading: const Icon(Icons.hub_outlined, size: 20),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: const AppText('OpenChamber'),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
trailing: _version(context, versions?.openchamber ?? ''),
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class LicensesPage extends StatefulWidget {
|
|
|
|
|
|
const LicensesPage({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<LicensesPage> createState() => _LicensesPageState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _LicensesPageState extends State<LicensesPage> {
|
|
|
|
|
|
Map<String, String>? _licenses;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
_collect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// One entry per package, the license text appended in the order Flutter
|
|
|
|
|
|
/// reports the notices.
|
|
|
|
|
|
Future<void> _collect() async {
|
|
|
|
|
|
final texts = <String, StringBuffer>{};
|
|
|
|
|
|
await for (final entry in LicenseRegistry.licenses) {
|
|
|
|
|
|
for (final package in entry.packages) {
|
|
|
|
|
|
texts.putIfAbsent(package, () => StringBuffer()).write(_text(entry));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
final names = texts.keys.toList()
|
|
|
|
|
|
..sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_licenses = {
|
|
|
|
|
|
for (final name in names) name: texts[name].toString().trim(),
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
final licenses = _licenses;
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: const AppText('开源许可')),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
body: licenses == null
|
|
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
|
|
|
|
|
: ListView.separated(
|
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 32),
|
|
|
|
|
|
itemCount: licenses.length + 1,
|
|
|
|
|
|
separatorBuilder: (_, __) =>
|
|
|
|
|
|
const Divider(height: 1, indent: 20, endIndent: 20),
|
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 14, 20, 14),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(
|
2026-11-25 12:39:48 +08:00
|
|
|
|
'下面列出随本应用打包的第三方组件;点开可阅读完整许可证。',
|
|
|
|
|
|
style:
|
|
|
|
|
|
TextStyle(fontSize: 12.5, color: theme.hintColor),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
final name = licenses.keys.elementAt(i - 1);
|
|
|
|
|
|
return ListTile(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(name),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
trailing: const Icon(Icons.chevron_right, size: 20),
|
|
|
|
|
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
|
builder: (_) => _LicenseTextPage(
|
|
|
|
|
|
name: name, text: licenses[name] ?? ''),
|
|
|
|
|
|
)),
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A license's paragraphs as one text, indented the way the license itself
|
|
|
|
|
|
/// asks (a centered paragraph is only trimmed).
|
|
|
|
|
|
String _text(LicenseEntry entry) {
|
|
|
|
|
|
final buffer = StringBuffer();
|
|
|
|
|
|
for (final paragraph in entry.paragraphs) {
|
|
|
|
|
|
if (buffer.isNotEmpty) buffer.write('\n\n');
|
|
|
|
|
|
final body = paragraph.text.trimRight();
|
|
|
|
|
|
if (paragraph.indent == LicenseParagraph.centeredIndent) {
|
|
|
|
|
|
buffer.write(body.trim());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
buffer.write('${' ' * (paragraph.indent < 0 ? 0 : paragraph.indent)}$body');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return buffer.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _LicenseTextPage extends StatelessWidget {
|
|
|
|
|
|
final String name;
|
|
|
|
|
|
final String text;
|
|
|
|
|
|
const _LicenseTextPage({required this.name, required this.text});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
appBar: AppBar(title: AppText(name)),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
|
child: SelectableText(
|
2026-11-26 09:04:25 +08:00
|
|
|
|
text.isEmpty ? tr('该组件没有附带许可证文本。') : text,
|
2026-11-25 12:39:48 +08:00
|
|
|
|
style: const TextStyle(fontSize: 12, fontFamily: 'monospace', height: 1.45),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------- chrome
|
|
|
|
|
|
|
|
|
|
|
|
class _Section extends StatelessWidget {
|
|
|
|
|
|
/// Rows of one category in a rounded block, separated by hairlines that
|
|
|
|
|
|
/// start at the text, the way the session list draws its groups.
|
|
|
|
|
|
final List<Widget> children;
|
|
|
|
|
|
const _Section({required this.children});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
|
|
|
|
child: Material(
|
|
|
|
|
|
color: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.45),
|
|
|
|
|
|
borderRadius: BorderRadius.circular(14),
|
|
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
for (var i = 0; i < children.length; i++) ...[
|
|
|
|
|
|
if (i > 0) const Divider(height: 1, indent: 56),
|
|
|
|
|
|
children[i],
|
|
|
|
|
|
],
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _NavTile extends StatelessWidget {
|
|
|
|
|
|
final IconData icon;
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
final String subtitle;
|
|
|
|
|
|
final WidgetBuilder builder;
|
|
|
|
|
|
|
|
|
|
|
|
const _NavTile({
|
|
|
|
|
|
required this.icon,
|
|
|
|
|
|
required this.title,
|
|
|
|
|
|
required this.subtitle,
|
|
|
|
|
|
required this.builder,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return ListTile(
|
|
|
|
|
|
leading: Icon(icon, size: 22),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
title: AppText(title),
|
|
|
|
|
|
subtitle: AppText(subtitle),
|
2026-11-25 12:39:48 +08:00
|
|
|
|
trailing: const Icon(Icons.chevron_right, size: 20),
|
|
|
|
|
|
onTap: () => Navigator.of(context)
|
|
|
|
|
|
.push(MaterialPageRoute(builder: builder)),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-21 19:17:22 +08:00
|
|
|
|
class _SectionHeader extends StatelessWidget {
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
final String? note;
|
|
|
|
|
|
const _SectionHeader(this.title, {this.note});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 18, 20, 6),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
2026-11-26 09:04:25 +08:00
|
|
|
|
AppText(title,
|
2026-11-21 19:17:22 +08:00
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
|
color: theme.colorScheme.primary,
|
|
|
|
|
|
)),
|
|
|
|
|
|
if (note != null)
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 2),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(note!,
|
2026-11-21 19:17:22 +08:00
|
|
|
|
style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _Label extends StatelessWidget {
|
|
|
|
|
|
final String text;
|
|
|
|
|
|
const _Label(this.text);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 2, 20, 6),
|
2026-11-26 09:04:25 +08:00
|
|
|
|
child: AppText(text,
|
2026-11-21 19:17:22 +08:00
|
|
|
|
style: const TextStyle(fontSize: 13.5, fontWeight: FontWeight.w500)),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|