feat(chat): segmented chat header with back, title and model pills
The open conversation draws its own bar of separate rounded pieces: the platform Back in a circle, a title pill with the folder that opens the chat information, and a pill with the model and mode controls. Detail pages drop only their app bar for it, keeping the body mounted.
This commit is contained in:
@@ -28,6 +28,7 @@ import 'chat_models.dart';
|
||||
import 'chat_row_keys.dart';
|
||||
import 'chat_scroll.dart';
|
||||
import 'chat_thread_controller.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_cache.dart';
|
||||
import 'chat_permission_card_model.dart';
|
||||
import 'chat_permission_group.dart';
|
||||
@@ -717,78 +718,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
final inShellBar = ShellBar.available(context);
|
||||
final column = Column(
|
||||
children: [
|
||||
// The conversation's own bar first, outside the transcript's scroller,
|
||||
// as on the web (chat-bar, then background tasks, then transcript).
|
||||
if (!inShellBar)
|
||||
Padding(
|
||||
key: const Key('chat-thread-header'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(4, 8, 4, 4),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final title = widget.title.trim();
|
||||
final session = widget.session;
|
||||
final hasModel =
|
||||
session != null &&
|
||||
supportsChatModels('${session['backend'] ?? ''}');
|
||||
// One compact row, as on the web: back, the conversation's
|
||||
// name, its model and the information action. The title
|
||||
// takes the remaining width and ellipsises; the model keeps
|
||||
// a bounded share so neither control is pushed off a narrow
|
||||
// 2x phone and the header never wraps onto a second line.
|
||||
return Row(
|
||||
children: [
|
||||
_backButton(cupertino),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
child: title.isEmpty
|
||||
? const SizedBox.shrink()
|
||||
: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: cupertino
|
||||
? CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.navTitleTextStyle
|
||||
: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasModel)
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.4,
|
||||
),
|
||||
child: ChatModelControl(
|
||||
key: ValueKey<String>(
|
||||
'chat-model-${widget.sessionId}',
|
||||
),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
session: session,
|
||||
onChanged: widget.onModelChanged,
|
||||
answeredBy: latestReplyModel(_controller.messages),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.3,
|
||||
),
|
||||
child: _modeControl(),
|
||||
),
|
||||
ChatBarAction(
|
||||
key: const Key('chat-info'),
|
||||
label: 'Chat information',
|
||||
onPressed: _openInfo,
|
||||
materialIcon: Icons.info_outline,
|
||||
cupertinoIcon: CupertinoIcons.info,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// The conversation's own floating bar, above its transcript.
|
||||
_header(context, inShellBar),
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: _onScrollMetrics,
|
||||
@@ -922,42 +853,60 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
],
|
||||
);
|
||||
if (!inShellBar) return column;
|
||||
final session = widget.session;
|
||||
final hasModel =
|
||||
session != null && supportsChatModels('${session['backend'] ?? ''}');
|
||||
// The conversation draws its own floating bar; the page shows none.
|
||||
final title = widget.title.trim();
|
||||
return ShellBar(
|
||||
barless: true,
|
||||
title: title.isEmpty ? null : title,
|
||||
actions: [
|
||||
if (hasModel)
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 180),
|
||||
child: ChatModelControl(
|
||||
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
session: session,
|
||||
onChanged: widget.onModelChanged,
|
||||
answeredBy: latestReplyModel(_controller.messages),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: _modeControl(),
|
||||
),
|
||||
ChatBarAction(
|
||||
key: const Key('chat-info'),
|
||||
label: 'Chat information',
|
||||
onPressed: _openInfo,
|
||||
materialIcon: Icons.info_outline,
|
||||
cupertinoIcon: CupertinoIcons.info,
|
||||
),
|
||||
],
|
||||
child: column,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/// The floating bar: Back where this page can go back (a pushed phone page,
|
||||
/// or a standalone screen), the title pill that opens the information, and
|
||||
/// the model and mode controls.
|
||||
Widget _header(BuildContext context, bool inShellBar) {
|
||||
final session = widget.session;
|
||||
final hasModel =
|
||||
session != null && supportsChatModels('${session['backend'] ?? ''}');
|
||||
final canGoBack = inShellBar
|
||||
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
||||
: true;
|
||||
final directory = '${session?['directory'] ?? ''}'.trim();
|
||||
final folder = directory
|
||||
.split(RegExp(r'[/\\]'))
|
||||
.lastWhere((part) => part.isNotEmpty, orElse: () => '');
|
||||
return ChatThreadHeader(
|
||||
key: const Key('chat-thread-header'),
|
||||
title: widget.title.trim(),
|
||||
folder: folder,
|
||||
onInfo: _openInfo,
|
||||
showBack: canGoBack,
|
||||
// A pushed page keeps the platform's stock Back (pop this route); a
|
||||
// standalone conversation calls its owner.
|
||||
onBack: inShellBar ? null : widget.onBack,
|
||||
controls: [
|
||||
if (hasModel)
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 160),
|
||||
child: ChatModelControl(
|
||||
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
session: session,
|
||||
onChanged: widget.onModelChanged,
|
||||
answeredBy: latestReplyModel(_controller.messages),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 140),
|
||||
child: _modeControl(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// The session's permission mode, keyed per session so another chat
|
||||
/// re-reads its own modes.
|
||||
Widget _modeControl() => ChatModeControl(
|
||||
@@ -1037,32 +986,6 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
images: _images,
|
||||
);
|
||||
}
|
||||
|
||||
/// The header's compact Back control, matching the web's icon-only control.
|
||||
/// Its accessible name states the destination; Material keeps a tooltip and
|
||||
/// Cupertino the same label on the wrapping node.
|
||||
Widget _backButton(bool cupertino) {
|
||||
const label = 'Back to chats';
|
||||
final icon = Icon(cupertino ? CupertinoIcons.back : Icons.arrow_back);
|
||||
if (!cupertino) {
|
||||
return IconButton(
|
||||
key: const Key('chat-back'),
|
||||
tooltip: label,
|
||||
onPressed: widget.onBack,
|
||||
icon: icon,
|
||||
);
|
||||
}
|
||||
return Semantics(
|
||||
label: label,
|
||||
button: true,
|
||||
child: CupertinoButton(
|
||||
key: const Key('chat-back'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onBack,
|
||||
child: icon,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The native dismiss control shared by a local notice and a running
|
||||
|
||||
Reference in New Issue
Block a user