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:
1 parent
885a27c6a9
commit
782ac2bd4d
3 files changed
+192
-77
No files matched your search
+186
-75
@@ -79,10 +79,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
title: Text(widget.session.title.isEmpty ? '会话' : widget.session.title,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.tune),
|
||||
tooltip: '模型与智能体',
|
||||
onPressed: () => _openPicker('model'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: ActionChip(
|
||||
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(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
@@ -518,87 +526,86 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
// ------------------------------------------------------------ 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() {
|
||||
final usage = chat.usageReading();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final canSend = _draftCtrl.text.trim().isNotEmpty || _attachments.isNotEmpty;
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 4),
|
||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (_attachments.isNotEmpty)
|
||||
SizedBox(
|
||||
height: 34,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
for (var i = 0; i < _attachments.length; i++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: InputChip(
|
||||
label: Text(_attachments[i].name,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
onDeleted: () => setState(() => _attachments.removeAt(i)),
|
||||
if (_attachments.isNotEmpty) _attachmentTray(),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(26),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_roundKey(
|
||||
icon: Icons.attach_file,
|
||||
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 {
|
||||
final text = _draftCtrl.text.trim();
|
||||
if (text.isEmpty && _attachments.isEmpty) return;
|
||||
@@ -630,6 +725,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
chat.imagePaths[id] = images;
|
||||
chat.touch();
|
||||
}
|
||||
HapticFeedback.lightImpact();
|
||||
}
|
||||
|
||||
Future<void> _pickFiles() async {
|
||||
@@ -763,11 +859,26 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
return Column(
|
||||
children: [
|
||||
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)),
|
||||
),
|
||||
Padding(
|
||||
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(
|
||||
onChanged: (v) => setState(() => _pickerFilter = v),
|
||||
decoration: const InputDecoration(hintText: '搜索', border: OutlineInputBorder(), isDense: true),
|
||||
|
||||
Reference in new issue
Block a user