feat: dsh-style composer and model chip

Follow dsh-Go's input bar (MIT, referenced rather than copied):

- one rounded capsule holding a leading 36px attach key, a borderless
  auto-growing field, the context usage ring and a trailing 36px key that
  sends, or becomes the stop button while a turn runs (the hint says
  "still typing while generating")
- attachment chips show image thumbnails above the capsule
- the app bar shows the current model and agent as a chip that opens the
  model/agent picker, now a segmented control
- light haptic on send
This commit is contained in:
blumia committed 2026-11-18 20:48:12 +08:00
1 parent 885a27c6a9
commit 782ac2bd4d
3 files changed
+192 -77

No files matched your search

+1
View File
@@ -18,6 +18,7 @@
| 复用 | Go 客户端无法复用;`lib/api/` 按同一协议重写(HTTP/SOCKS5 代理、自签/pinning、SSE、part-shells);聊天 Markdown 直接采用 **dsh-Go 同款的 `gpt_markdown`**(BSD-3,流式、代码高亮/复制、表格、LaTeX、任务列表) | | 复用 | Go 客户端无法复用;`lib/api/` 按同一协议重写(HTTP/SOCKS5 代理、自签/pinning、SSE、part-shells);聊天 Markdown 直接采用 **dsh-Go 同款的 `gpt_markdown`**(BSD-3,流式、代码高亮/复制、表格、LaTeX、任务列表) |
| 踩坑 | SSE 的 `types` 是重复 query 参数,Dart 的 `Map` 会把它压成最后一个 → 只订阅到一种事件、聊天不更新;改为手动拼 query 后实时流恢复 | | 踩坑 | SSE 的 `types` 是重复 query 参数,Dart 的 `Map` 会把它压成最后一个 → 只订阅到一种事件、聊天不更新;改为手动拼 query 后实时流恢复 |
| 可继续复用 | dsh-Go 的 `app/lib/ui/chat/render/`(markdown_body、code_block、markdown_blocks 等)文件头多为 MIT,可保留 SPDX 头后搬运,但依赖其 Riverpod/DSH 协议类型;`scrollable_positioned_list`、`xterm` 等 pub 包也可直接用 | | 可继续复用 | dsh-Go 的 `app/lib/ui/chat/render/`(markdown_body、code_block、markdown_blocks 等)文件头多为 MIT,可保留 SPDX 头后搬运,但依赖其 Riverpod/DSH 协议类型;`scrollable_positioned_list`、`xterm` 等 pub 包也可直接用 |
| 输入区(参考 dsh-Go) | 圆角胶囊 + 左侧 36 圆附件键 + 无边框自动增高输入 + 上下文占用环 + 右侧 36 圆发送/停止键(运行中变为停止、hint 变「生成中,仍可输入…」);附件以缩略图 chip 展开在胶囊上方;顶栏模型 chip(点击打开模型/智能体分段选择) |
| 最低 Android | **24(7.0)** | | 最低 Android | **24(7.0)** |
| 明文 HTTP | Dart `HttpClient` 直接建 socket,release 连 `http://` 无需 cleartext 开关(已实测) | | 明文 HTTP | Dart `HttpClient` 直接建 socket,release 连 `http://` 无需 cleartext 开关(已实测) |
| 模拟器实测 | 服务器列表→添加/连接(无密码自动跳过)→会话列表(运行点/模型·时间)→聊天:流式 Markdown(gpt_markdown,代码块/表格实测)、思考/工具行、页脚、上下文占用环、输入与实时回复(SSE) | | 模拟器实测 | 服务器列表→添加/连接(无密码自动跳过)→会话列表(运行点/模型·时间)→聊天:流式 Markdown(gpt_markdown,代码块/表格实测)、思考/工具行、页脚、上下文占用环、输入与实时回复(SSE) |
+5 -2
View File
@@ -23,8 +23,11 @@ revert, attachments (photos/files), permissions. Android 7.0 (API 24)+.
Markdown rendering reuses **`gpt_markdown`** (BSD-3), the Flutter AI-output renderer Markdown rendering reuses **`gpt_markdown`** (BSD-3), the Flutter AI-output renderer
that [dsh-Go](https://github.com/ccch1mneyyy/dsh-go) uses: streaming-friendly, that [dsh-Go](https://github.com/ccch1mneyyy/dsh-go) uses: streaming-friendly,
syntax-highlighted code blocks with copy, tables, LaTeX and task lists. Read-aloud syntax-highlighted code blocks with copy, tables, LaTeX and task lists. The input
(TTS) is intentionally **not** implemented (matching the original). bar and the model chip follow dsh-Go's composer design (MIT, referenced rather
than copied): a rounded capsule, a leading attach key, an auto-growing borderless
field, the usage ring, and a 36px send/stop key that morphs while a turn runs.
Read-aloud (TTS) is intentionally **not** implemented (matching the original).
## Run ## Run
+186 -75
View File
@@ -79,10 +79,18 @@ class _ChatScreenState extends State<ChatScreen> {
title: Text(widget.session.title.isEmpty ? '会话' : widget.session.title, title: Text(widget.session.title.isEmpty ? '会话' : widget.session.title,
maxLines: 1, overflow: TextOverflow.ellipsis), maxLines: 1, overflow: TextOverflow.ellipsis),
actions: [ actions: [
IconButton( Padding(
icon: const Icon(Icons.tune), padding: const EdgeInsets.only(right: 4),
tooltip: '模型与智能体', child: ActionChip(
onPressed: () => _openPicker('model'), visualDensity: VisualDensity.compact,
avatar: const Icon(Icons.smart_toy_outlined, size: 16),
label: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 120),
child: Text(_modelLabel(),
maxLines: 1, overflow: TextOverflow.ellipsis),
),
onPressed: () => _openPicker('model'),
),
), ),
IconButton( IconButton(
icon: const Icon(Icons.more_vert), icon: const Icon(Icons.more_vert),
@@ -518,87 +526,86 @@ class _ChatScreenState extends State<ChatScreen> {
// ------------------------------------------------------------ composer // ------------------------------------------------------------ composer
// The composer follows dsh-Go's input bar: a rounded capsule holding a
// leading key, an auto-growing borderless field, the usage ring and a
// trailing send/stop key, all 36px round keys (MIT, app/lib/ui/chat/
// composer.dart, referenced rather than copied).
Widget _composer() { Widget _composer() {
final usage = chat.usageReading(); final usage = chat.usageReading();
final scheme = Theme.of(context).colorScheme;
final canSend = _draftCtrl.text.trim().isNotEmpty || _attachments.isNotEmpty;
return SafeArea( return SafeArea(
top: false, top: false,
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(8, 6, 8, 4), padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (_attachments.isNotEmpty) if (_attachments.isNotEmpty) _attachmentTray(),
SizedBox( Container(
height: 34, padding: const EdgeInsets.all(6),
child: ListView( decoration: BoxDecoration(
scrollDirection: Axis.horizontal, color: scheme.surfaceContainerHighest,
children: [ borderRadius: BorderRadius.circular(26),
for (var i = 0; i < _attachments.length; i++) ),
Padding( child: Row(
padding: const EdgeInsets.only(right: 6), crossAxisAlignment: CrossAxisAlignment.end,
child: InputChip( children: [
label: Text(_attachments[i].name, _roundKey(
maxLines: 1, overflow: TextOverflow.ellipsis), icon: Icons.attach_file,
onDeleted: () => setState(() => _attachments.removeAt(i)), label: '添加附件',
onTap: _pickFiles,
busy: _attaching,
),
const SizedBox(width: 4),
Expanded(
child: TextField(
controller: _draftCtrl,
minLines: 1,
maxLines: 5,
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
onChanged: (v) {
chat.draft = v;
setState(() {});
},
style: const TextStyle(fontSize: 15, height: 1.45),
decoration: InputDecoration(
hintText: chat.running ? '生成中,仍可输入…' : '发消息…',
hintMaxLines: 1,
isDense: true,
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 8),
),
),
),
if (usage.$5)
InkWell(
onTap: () => _usageSheet(context),
borderRadius: BorderRadius.circular(20),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
UsageRing(pct: usage.$4, size: 16, accent: scheme.primary),
const SizedBox(width: 3),
Text('${usage.$4.round()}%',
style: TextStyle(fontSize: 12, color: scheme.onSurfaceVariant)),
],
), ),
), ),
], ),
), const SizedBox(width: 2),
_roundKey(
icon: chat.running ? Icons.stop_rounded : Icons.arrow_upward_rounded,
label: chat.running ? '停止' : '发送',
filled: true,
enabled: chat.running || canSend,
onTap: chat.running ? chat.stop : _send,
),
],
), ),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
_attaching
? const Padding(
padding: EdgeInsets.all(12),
child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)))
: IconButton(
icon: const Icon(Icons.attach_file),
tooltip: '添加附件',
onPressed: _pickFiles,
),
Expanded(
child: TextField(
controller: _draftCtrl,
minLines: 1,
maxLines: 5,
onChanged: (v) => chat.draft = v,
decoration: const InputDecoration(
hintText: '发消息…',
border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
),
),
if (usage.$5)
InkWell(
onTap: () => _usageSheet(context),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
UsageRing(pct: usage.$4, accent: Theme.of(context).colorScheme.primary),
const SizedBox(width: 4),
Text('${usage.$4.round()}%',
style: const TextStyle(fontSize: 13, color: Colors.grey)),
],
),
),
),
if (chat.running)
IconButton(
icon: const Icon(Icons.stop),
tooltip: '停止',
onPressed: chat.stop,
)
else
IconButton.filled(
icon: const Icon(Icons.send),
tooltip: '发送',
onPressed: () => _send(),
),
],
), ),
], ],
), ),
@@ -606,6 +613,94 @@ class _ChatScreenState extends State<ChatScreen> {
); );
} }
/// One 36px round key of the input bar.
Widget _roundKey({
required IconData icon,
required String label,
required VoidCallback onTap,
bool filled = false,
bool enabled = true,
bool busy = false,
}) {
final scheme = Theme.of(context).colorScheme;
final on = enabled && !busy;
final bg = filled
? (on ? scheme.primary : scheme.onSurface.withValues(alpha: 0.12))
: scheme.onSurface.withValues(alpha: 0.06);
final fg = filled
? (on ? scheme.onPrimary : scheme.onSurface.withValues(alpha: 0.38))
: scheme.onSurface;
return Semantics(
button: true,
enabled: on,
label: label,
child: Material(
color: bg,
shape: const CircleBorder(),
child: InkWell(
customBorder: const CircleBorder(),
onTap: on ? onTap : null,
child: SizedBox(
width: 36,
height: 36,
child: Center(
child: busy
? SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2, color: fg),
)
: Icon(icon, size: 20, color: fg),
),
),
),
),
);
}
/// Attachment chips with a thumbnail, unfolded above the input bar.
Widget _attachmentTray() {
return SizedBox(
height: 46,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
for (var i = 0; i < _attachments.length; i++)
Padding(
padding: const EdgeInsets.only(right: 6),
child: InputChip(
avatar: _attachments[i].path != null
? CircleAvatar(
backgroundImage: FileImage(File(_attachments[i].path!)),
)
: const Icon(Icons.insert_drive_file, size: 16),
label: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 160),
child: Text(_attachments[i].name,
maxLines: 1, overflow: TextOverflow.ellipsis),
),
onDeleted: () => setState(() => _attachments.removeAt(i)),
),
),
],
),
);
}
String _modelLabel() {
ModelRef? m;
for (var i = chat.msgs.length - 1; i >= 0; i--) {
if (chat.msgs[i].model != null) {
m = chat.msgs[i].model;
break;
}
}
m ??= widget.session.model;
final model = m == null ? '模型' : widget.app.modelName(m);
final agent = widget.session.agent;
return agent.isEmpty ? model : '$model · $agent';
}
Future<void> _send() async { Future<void> _send() async {
final text = _draftCtrl.text.trim(); final text = _draftCtrl.text.trim();
if (text.isEmpty && _attachments.isEmpty) return; if (text.isEmpty && _attachments.isEmpty) return;
@@ -630,6 +725,7 @@ class _ChatScreenState extends State<ChatScreen> {
chat.imagePaths[id] = images; chat.imagePaths[id] = images;
chat.touch(); chat.touch();
} }
HapticFeedback.lightImpact();
} }
Future<void> _pickFiles() async { Future<void> _pickFiles() async {
@@ -763,11 +859,26 @@ class _ChatScreenState extends State<ChatScreen> {
return Column( return Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.fromLTRB(12, 12, 12, 4),
child: Text(title, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), child: Text(title, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 12), padding: const EdgeInsets.symmetric(horizontal: 12),
child: SegmentedButton<String>(
segments: const [
ButtonSegment(value: 'model', label: Text('模型')),
ButtonSegment(value: 'agent', label: Text('智能体')),
],
selected: {_pickerKind},
showSelectedIcon: false,
onSelectionChanged: (s) {
setState(() => _pickerKind = s.first);
widget.app.refreshModels();
},
),
),
Padding(
padding: const EdgeInsets.all(12),
child: TextField( child: TextField(
onChanged: (v) => setState(() => _pickerFilter = v), onChanged: (v) => setState(() => _pickerFilter = v),
decoration: const InputDecoration(hintText: '搜索', border: OutlineInputBorder(), isDense: true), decoration: const InputDecoration(hintText: '搜索', border: OutlineInputBorder(), isDense: true),