fix(app): float the chat composer as glass, cap the reading width, tidy chat chrome
This commit is contained in:
@@ -28,7 +28,9 @@ import 'chat_models.dart';
|
||||
import 'chat_row_keys.dart';
|
||||
import 'chat_scroll.dart';
|
||||
import 'chat_thread_controller.dart';
|
||||
import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_cache.dart';
|
||||
import 'chat_permission_card_model.dart';
|
||||
@@ -717,124 +719,147 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
// Under the app shell the conversation takes over the app's bar (title,
|
||||
// Back, model, information) instead of drawing a second bar below it.
|
||||
final inShellBar = ShellBar.available(context);
|
||||
final column = Column(
|
||||
children: [
|
||||
Expanded(
|
||||
// The conversation's own bar floats over its transcript, which
|
||||
// scrolls behind it.
|
||||
child: SegmentedBarOverlay(
|
||||
bar: _header(context, inShellBar),
|
||||
child: NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: _onScrollMetrics,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: _onScrollNotification,
|
||||
child: Stack(
|
||||
// The transcript fills the page; the conversation's bar floats over its
|
||||
// top and the frosted composer over its bottom, and history scrolls
|
||||
// behind both.
|
||||
final column = FloatingBarOverlay(
|
||||
bar: ChatComposerBar(
|
||||
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
||||
composer: _composer,
|
||||
running: _controller.running,
|
||||
commands: _commandActions(),
|
||||
picker: widget.attachmentPicker,
|
||||
images: _images,
|
||||
placeholder: chatComposerPlaceholderFor(
|
||||
'${widget.session?['directory'] ?? ''}',
|
||||
),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
syncToken: widget.syncToken,
|
||||
),
|
||||
),
|
||||
child: SegmentedBarOverlay(
|
||||
bar: _header(context, inShellBar),
|
||||
child: NotificationListener<ScrollMetricsNotification>(
|
||||
onNotification: _onScrollMetrics,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: _onScrollNotification,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Rows keep to the centred reading column on a wide
|
||||
// window; the margins beside it still scroll the list.
|
||||
final side = chatReadingInset(constraints.maxWidth);
|
||||
final media = MediaQuery.paddingOf(context);
|
||||
return Stack(
|
||||
children: [
|
||||
Builder(
|
||||
// At rest the first item starts below the floating bar.
|
||||
builder: (context) => ListView(
|
||||
key: ValueKey<String>(
|
||||
'chat-thread-${widget.sessionId}',
|
||||
),
|
||||
controller: _scroll,
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.paddingOf(context).top + 8,
|
||||
bottom: 8,
|
||||
),
|
||||
children: [
|
||||
if (initialLoad)
|
||||
Padding(
|
||||
key: const Key('chat-thread-loading'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
if (_controller.hasMore)
|
||||
Padding(
|
||||
key: const Key('chat-load-older'),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.loading
|
||||
? null
|
||||
: _controller.loadOlder,
|
||||
child: const Text('Load older'),
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: _controller.loading
|
||||
? null
|
||||
: _controller.loadOlder,
|
||||
child: const Text('Load older'),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (historyNotice != null)
|
||||
_ChatNoticeLine(
|
||||
key: const Key('chat-history-error'),
|
||||
notice: historyNotice,
|
||||
onDismiss: _dismiss,
|
||||
onRetry: _controller.load,
|
||||
),
|
||||
if (liveNotice != null)
|
||||
_ChatNoticeLine(
|
||||
key: const Key('chat-live-error'),
|
||||
notice: liveNotice,
|
||||
onDismiss: _dismiss,
|
||||
onRetry: _controller.resync,
|
||||
),
|
||||
if (_controller.loaded &&
|
||||
allRows.isEmpty &&
|
||||
allNotices.isEmpty &&
|
||||
_commandNotices.isEmpty &&
|
||||
_controller.error == null)
|
||||
const Padding(
|
||||
key: Key('chat-thread-empty'),
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No messages in this chat yet.'),
|
||||
),
|
||||
for (var index = 0; index < rows.length; index++)
|
||||
Padding(
|
||||
key: ValueKey<String>(keys[index]),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
),
|
||||
child: _transcriptRow(
|
||||
rows[index],
|
||||
onDismissCompaction:
|
||||
compactionNotice != null &&
|
||||
chatNoticeActivityCondition(
|
||||
rows[index],
|
||||
) ==
|
||||
compactionNotice.condition
|
||||
? () => _dismiss(compactionNotice)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
// The conversation's own command lines sit after the
|
||||
// turns, as on the web; they are never bubbles.
|
||||
for (final notice in _commandNotices)
|
||||
_ChatNoticeLine(
|
||||
key: ValueKey<String>(
|
||||
'chat-command-notice-${notice.condition}',
|
||||
),
|
||||
notice: notice,
|
||||
onDismiss: _dismiss,
|
||||
),
|
||||
],
|
||||
// At rest the first item starts below the floating bar
|
||||
// and the last one ends above the floating composer.
|
||||
ListView(
|
||||
key: ValueKey<String>(
|
||||
'chat-thread-${widget.sessionId}',
|
||||
),
|
||||
controller: _scroll,
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
side,
|
||||
media.top + 8,
|
||||
side,
|
||||
media.bottom + 8,
|
||||
),
|
||||
children: [
|
||||
if (initialLoad)
|
||||
Padding(
|
||||
key: const Key('chat-thread-loading'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
if (_controller.hasMore)
|
||||
Padding(
|
||||
key: const Key('chat-load-older'),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.loading
|
||||
? null
|
||||
: _controller.loadOlder,
|
||||
child: const Text('Load older'),
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: _controller.loading
|
||||
? null
|
||||
: _controller.loadOlder,
|
||||
child: const Text('Load older'),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (historyNotice != null)
|
||||
_ChatNoticeLine(
|
||||
key: const Key('chat-history-error'),
|
||||
notice: historyNotice,
|
||||
onDismiss: _dismiss,
|
||||
onRetry: _controller.load,
|
||||
),
|
||||
if (liveNotice != null)
|
||||
_ChatNoticeLine(
|
||||
key: const Key('chat-live-error'),
|
||||
notice: liveNotice,
|
||||
onDismiss: _dismiss,
|
||||
onRetry: _controller.resync,
|
||||
),
|
||||
if (_controller.loaded &&
|
||||
allRows.isEmpty &&
|
||||
allNotices.isEmpty &&
|
||||
_commandNotices.isEmpty &&
|
||||
_controller.error == null)
|
||||
const Padding(
|
||||
key: Key('chat-thread-empty'),
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No messages in this chat yet.'),
|
||||
),
|
||||
for (var index = 0; index < rows.length; index++)
|
||||
Padding(
|
||||
key: ValueKey<String>(keys[index]),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
),
|
||||
child: _transcriptRow(
|
||||
rows[index],
|
||||
onDismissCompaction:
|
||||
compactionNotice != null &&
|
||||
chatNoticeActivityCondition(
|
||||
rows[index],
|
||||
) ==
|
||||
compactionNotice.condition
|
||||
? () => _dismiss(compactionNotice)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
// The conversation's own command lines sit after the
|
||||
// turns, as on the web; they are never bubbles.
|
||||
for (final notice in _commandNotices)
|
||||
_ChatNoticeLine(
|
||||
key: ValueKey<String>(
|
||||
'chat-command-notice-${notice.condition}',
|
||||
),
|
||||
notice: notice,
|
||||
onDismiss: _dismiss,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (showJump)
|
||||
PositionedDirectional(
|
||||
end: 16,
|
||||
bottom: 16,
|
||||
end: side + 16,
|
||||
bottom: media.bottom + 16,
|
||||
child: _ChatJumpToLatest(
|
||||
key: const Key('chat-jump-to-latest'),
|
||||
label: chatJumpToLatestLabel(newMessages),
|
||||
@@ -843,29 +868,12 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
ChatComposerBar(
|
||||
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
||||
composer: _composer,
|
||||
running: _controller.running,
|
||||
commands: _commandActions(),
|
||||
picker: widget.attachmentPicker,
|
||||
images: _images,
|
||||
placeholder: chatComposerPlaceholderFor(
|
||||
'${widget.session?['directory'] ?? ''}',
|
||||
),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
syncToken: widget.syncToken,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (!inShellBar) return column;
|
||||
// The conversation draws its own floating bar; the page shows none.
|
||||
@@ -885,6 +893,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
final session = widget.session;
|
||||
final hasModel =
|
||||
session != null && supportsChatModels('${session['backend'] ?? ''}');
|
||||
// The mode control has nothing to show (or change) without both facts.
|
||||
final hasMode =
|
||||
'${session?['mode'] ?? ''}'.trim().isNotEmpty &&
|
||||
'${session?['mode_name'] ?? ''}'.trim().isNotEmpty;
|
||||
final canGoBack = inShellBar
|
||||
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
||||
: true;
|
||||
@@ -901,23 +913,40 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
// A pushed page keeps the platform's stock Back (pop this route); a
|
||||
// standalone conversation calls its owner.
|
||||
onBack: inShellBar ? null : widget.onBack,
|
||||
// Natural width while the bar has room; past the title's share both
|
||||
// controls ellipsise. A session without a mode draws no mode control,
|
||||
// so no empty pill is ever drawn.
|
||||
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),
|
||||
if (hasModel || hasMode)
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (hasModel)
|
||||
Flexible(
|
||||
child: ChatModelControl(
|
||||
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: widget.sessionId,
|
||||
session: session,
|
||||
onChanged: widget.onModelChanged,
|
||||
answeredBy: latestReplyModel(_controller.messages),
|
||||
),
|
||||
),
|
||||
if (hasMode)
|
||||
// The mode keeps its whole name until it would take more
|
||||
// than half the pill; the model takes the rest.
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: hasModel
|
||||
? constraints.maxWidth / 2
|
||||
: constraints.maxWidth,
|
||||
),
|
||||
child: _modeControl(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 140),
|
||||
child: _modeControl(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user