fix(app): float the chat composer as glass, cap the reading width, tidy chat chrome
This commit is contained in:
@@ -7,7 +7,8 @@ import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_background_tasks_controller.dart';
|
||||
import 'chat_background_tasks_panel.dart';
|
||||
|
||||
/// Compact live task count, mounted above Send. Details live only in its modal.
|
||||
/// Compact live task count: a quiet control inside the composer beside Send,
|
||||
/// shown only while tasks run. Details live only in its modal.
|
||||
class ChatBackgroundTasks extends StatefulWidget {
|
||||
const ChatBackgroundTasks({
|
||||
super.key,
|
||||
@@ -109,43 +110,63 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
|
||||
listenable: controller,
|
||||
builder: (context, _) {
|
||||
final count = controller.running.length;
|
||||
final label = controller.error != null
|
||||
final failed = controller.error != null;
|
||||
// Nothing to show without running tasks: never a "0 tasks" caption. A
|
||||
// list that cannot be read stays reachable so its refusal is reported.
|
||||
if (count == 0 && !failed) return const SizedBox.shrink();
|
||||
final label = failed
|
||||
? 'Tasks'
|
||||
: controller.loading && count == 0
|
||||
? 'Tasks…'
|
||||
: '$count ${count == 1 ? 'task' : 'tasks'}';
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final button = cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('chat-background-tasks-button'),
|
||||
sizeStyle: CupertinoButtonSize.small,
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _open,
|
||||
child: Text(
|
||||
final Widget button;
|
||||
if (cupertino) {
|
||||
final color = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
button = CupertinoButton(
|
||||
key: const Key('chat-background-tasks-button'),
|
||||
sizeStyle: CupertinoButtonSize.small,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
onPressed: _open,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(CupertinoIcons.square_stack_3d_up, size: 16, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle
|
||||
.copyWith(color: CupertinoTheme.of(context).primaryColor),
|
||||
style: CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.tabLabelTextStyle.copyWith(color: color),
|
||||
),
|
||||
)
|
||||
: TextButton(
|
||||
key: const Key('chat-background-tasks-button'),
|
||||
onPressed: _open,
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
return Semantics(
|
||||
button: true,
|
||||
excludeSemantics: true,
|
||||
onTap: _open,
|
||||
label: controller.error != null
|
||||
? 'Background tasks unavailable'
|
||||
: 'Background tasks, $label',
|
||||
child: button,
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final theme = Theme.of(context);
|
||||
button = TextButton.icon(
|
||||
key: const Key('chat-background-tasks-button'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: theme.colorScheme.onSurfaceVariant,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
onPressed: _open,
|
||||
icon: const Icon(Icons.layers_outlined, size: 16),
|
||||
label: Text(label, style: theme.textTheme.labelSmall),
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
// Level with the field's single line, beside Send.
|
||||
padding: const EdgeInsetsDirectional.only(end: 4, bottom: 4),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
excludeSemantics: true,
|
||||
onTap: _open,
|
||||
label: failed
|
||||
? 'Background tasks unavailable'
|
||||
: 'Background tasks, $label',
|
||||
child: button,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The conversation bar's model and mode controls read as the bar's other
|
||||
/// actions do: neutral, not tinted like a primary call to action.
|
||||
///
|
||||
/// Material: a [TextButton] style in the role the bar's icon buttons use
|
||||
/// (`onSurfaceVariant`).
|
||||
ButtonStyle chatBarTextButtonStyle(BuildContext context) =>
|
||||
TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
);
|
||||
|
||||
/// Cupertino: [content] (a [CupertinoButton]'s child) in the label colour
|
||||
/// instead of the button's tint.
|
||||
Widget chatBarCupertinoContent(BuildContext context, Widget content) {
|
||||
final color = CupertinoColors.label.resolveFrom(context);
|
||||
return IconTheme.merge(
|
||||
data: IconThemeData(color: color),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: TextStyle(color: color),
|
||||
child: content,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -21,6 +21,8 @@ import 'chat_command_actions.dart';
|
||||
import 'chat_command_palette.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
import '../ui/transcript/chat_attachment_frame.dart';
|
||||
import '../../../ui/adaptive/glass_pill.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
|
||||
/// The composer's placeholder when the chat names no working directory.
|
||||
const String chatComposerPlaceholder = 'Message the agent';
|
||||
@@ -612,87 +614,119 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
final selected = commands.isEmpty
|
||||
? 0
|
||||
: _selectedCommand % commands.length;
|
||||
// Everything the next message carries (attachments, its notices) sits
|
||||
// inside the glass with the field, as one floating composer; only the
|
||||
// command palette, a separate menu, floats above it.
|
||||
final extras = <Widget>[
|
||||
if (!_attachments.isEmpty) _attachmentStrip(context, cupertino),
|
||||
if (_uploading)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-uploading'),
|
||||
text: _attachments.attachments.length == 1
|
||||
? 'Uploading 1 file…'
|
||||
: 'Uploading ${_attachments.attachments.length} files…',
|
||||
),
|
||||
if (_attachmentError != null)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-attachment-error'),
|
||||
text: _attachmentError!,
|
||||
failed: true,
|
||||
),
|
||||
if (_commandNotice != null) _commandReport(context, cupertino),
|
||||
if (composer.queued)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-queued'),
|
||||
text: chatQueuedNotice,
|
||||
),
|
||||
if (error != null)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-error'),
|
||||
text: error,
|
||||
failed: true,
|
||||
),
|
||||
];
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
key: const Key('chat-composer'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (commands.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
||||
child: ChatCommandPalette(
|
||||
commands: commands,
|
||||
selectedIndex: selected,
|
||||
onSelected: _completeCommand,
|
||||
),
|
||||
),
|
||||
if (!_attachments.isEmpty) _attachmentStrip(context, cupertino),
|
||||
if (_uploading)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-uploading'),
|
||||
text: _attachments.attachments.length == 1
|
||||
? 'Uploading 1 file…'
|
||||
: 'Uploading ${_attachments.attachments.length} files…',
|
||||
),
|
||||
if (_attachmentError != null)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-attachment-error'),
|
||||
text: _attachmentError!,
|
||||
failed: true,
|
||||
),
|
||||
if (_commandNotice != null) _commandReport(context, cupertino),
|
||||
if (composer.queued)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-queued'),
|
||||
text: chatQueuedNotice,
|
||||
),
|
||||
if (error != null)
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-error'),
|
||||
text: error,
|
||||
failed: true,
|
||||
),
|
||||
if (widget.backgroundTasks != null)
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: widget.backgroundTasks!,
|
||||
),
|
||||
_pill(
|
||||
context,
|
||||
cupertino,
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_attach(context, cupertino),
|
||||
Expanded(
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
includeSemantics: false,
|
||||
onKeyEvent: _onKey,
|
||||
child: _field(cupertino),
|
||||
// The composer floats over the transcript in the conversation's
|
||||
// centred reading column; the space beside it passes taps through.
|
||||
child: Align(
|
||||
heightFactor: 1,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: kChatReadingWidth),
|
||||
child: Padding(
|
||||
key: const Key('chat-composer'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (commands.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
||||
child: ChatCommandPalette(
|
||||
commands: commands,
|
||||
selectedIndex: selected,
|
||||
onSelected: _completeCommand,
|
||||
),
|
||||
),
|
||||
if (widget.running) ...[
|
||||
_primary(context, cupertino, stop: true),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
_primary(context, cupertino),
|
||||
],
|
||||
),
|
||||
_pill(
|
||||
context,
|
||||
cupertino,
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (extras.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
12,
|
||||
8,
|
||||
12,
|
||||
0,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: extras,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_attach(context, cupertino),
|
||||
Expanded(
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
includeSemantics: false,
|
||||
onKeyEvent: _onKey,
|
||||
child: _field(cupertino),
|
||||
),
|
||||
),
|
||||
// Shown only while tasks run (or their list
|
||||
// cannot be read); a quiet control, not a
|
||||
// caption.
|
||||
?widget.backgroundTasks,
|
||||
if (widget.running) ...[
|
||||
_primary(context, cupertino, stop: true),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
_primary(context, cupertino),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -700,22 +734,17 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The field and its controls in one rounded filled surface, in the host's
|
||||
/// own fill role, so the composer reads as a single input rather than a row
|
||||
/// of separate controls.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) {
|
||||
final fill = cupertino
|
||||
? CupertinoColors.systemGrey6.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
return DecoratedBox(
|
||||
key: const Key('chat-composer-pill'),
|
||||
decoration: BoxDecoration(
|
||||
color: fill,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(28)),
|
||||
),
|
||||
child: Padding(padding: const EdgeInsets.all(4), child: child),
|
||||
);
|
||||
}
|
||||
/// The field and its controls in one frosted-glass surface floating over
|
||||
/// the transcript, so the composer reads as a single input rather than a
|
||||
/// row of separate controls, and the conversation shows through it.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) => GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
cupertino: cupertino,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(28)),
|
||||
),
|
||||
child: Padding(padding: const EdgeInsets.all(4), child: child),
|
||||
);
|
||||
|
||||
/// The attach control: a host button that opens the picker, disabled when the
|
||||
/// host has no picker or one prompt is already awaiting its reply.
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../core/api_gateway.dart';
|
||||
import '../../../core/error_reason.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_bar_control_style.dart';
|
||||
|
||||
/// The conversation bar's permission-mode control.
|
||||
///
|
||||
@@ -118,14 +119,19 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
key: key,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Tooltip(
|
||||
message: 'Change mode (currently $label)',
|
||||
child: TextButton(key: key, onPressed: _open, child: content),
|
||||
child: TextButton(
|
||||
key: key,
|
||||
style: chatBarTextButtonStyle(context),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_bar_control_style.dart';
|
||||
import 'chat_model_chooser.dart';
|
||||
import 'chat_models.dart';
|
||||
|
||||
@@ -135,14 +136,19 @@ class _ChatModelControlState extends State<ChatModelControl> {
|
||||
key: key,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Tooltip(
|
||||
message: 'Change model (currently $label)',
|
||||
child: TextButton(key: key, onPressed: _open, child: content),
|
||||
child: TextButton(
|
||||
key: key,
|
||||
style: chatBarTextButtonStyle(context),
|
||||
onPressed: _open,
|
||||
child: content,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
/// The widest the conversation's reading column grows: transcript rows and
|
||||
/// the floating composer share it, centred, so a wide window keeps a
|
||||
/// comfortable line length instead of stretching messages edge to edge.
|
||||
const double kChatReadingWidth = 760;
|
||||
|
||||
/// The space on each side of the centred reading column in [width].
|
||||
double chatReadingInset(double width) =>
|
||||
math.max(0, (width - kChatReadingWidth) / 2);
|
||||
@@ -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(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -193,66 +193,75 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
return ListenableBuilder(
|
||||
listenable: _controller,
|
||||
builder: (context, _) {
|
||||
final controls = chatControlsStyleOf(context);
|
||||
final body = Column(
|
||||
children: [
|
||||
if (_controller.error != null)
|
||||
ChatErrorNotice(
|
||||
message: _controller.error!,
|
||||
onRetry: _controller.refresh,
|
||||
),
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
ContentWidth(
|
||||
child: ChatSessionsBody(
|
||||
sessions: _controller.sessions,
|
||||
activeSessionId: widget.activeSessionId,
|
||||
query: _search.text,
|
||||
loading: _controller.loading,
|
||||
error: _controller.error,
|
||||
onOpen: _open,
|
||||
onRename: _rename,
|
||||
onClose: _close,
|
||||
onReopen: (session) =>
|
||||
_controller.reopen(_sessionId(session)),
|
||||
onStar: (session) => _controller.star(
|
||||
_sessionId(session),
|
||||
session['starred'] != true,
|
||||
),
|
||||
onHide: _hide,
|
||||
onClearSearch: () {
|
||||
_search.clear();
|
||||
setState(() {});
|
||||
},
|
||||
isUnseen: _controller.isUnseen,
|
||||
errorFor: _controller.errorFor,
|
||||
onDismissError: _controller.dismissError,
|
||||
),
|
||||
// Built under the page's scaffold, whose media padding carries the
|
||||
// floating bar's height.
|
||||
final body = Builder(
|
||||
builder: (context) => Column(
|
||||
children: [
|
||||
// A notice above the list starts below the floating bar; the list
|
||||
// under it then needs no inset of its own.
|
||||
if (_controller.error != null)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.paddingOf(context).top,
|
||||
),
|
||||
// The web's hide report is a fixed overlay: replacing or
|
||||
// growing it must never move the list or overflow the screen.
|
||||
// A standalone Material screen keeps it clear of the FAB.
|
||||
if (_controller.lastHidden != null)
|
||||
Positioned(
|
||||
left: 8,
|
||||
right: 8,
|
||||
bottom:
|
||||
!widget.embedded &&
|
||||
controls == ChatControlsStyle.material
|
||||
? 88
|
||||
: 8,
|
||||
child: ChatUndoBar(
|
||||
key: const Key('chat-undo-hide'),
|
||||
message:
|
||||
'Hidden on this device; the chat stays on the server.',
|
||||
onUndo: _undoHide,
|
||||
child: ChatErrorNotice(
|
||||
message: _controller.error!,
|
||||
onRetry: _controller.refresh,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: _controller.error != null,
|
||||
child: Stack(
|
||||
children: [
|
||||
ContentWidth(
|
||||
child: ChatSessionsBody(
|
||||
sessions: _controller.sessions,
|
||||
activeSessionId: widget.activeSessionId,
|
||||
query: _search.text,
|
||||
loading: _controller.loading,
|
||||
error: _controller.error,
|
||||
onOpen: _open,
|
||||
onRename: _rename,
|
||||
onClose: _close,
|
||||
onReopen: (session) =>
|
||||
_controller.reopen(_sessionId(session)),
|
||||
onStar: (session) => _controller.star(
|
||||
_sessionId(session),
|
||||
session['starred'] != true,
|
||||
),
|
||||
onHide: _hide,
|
||||
onClearSearch: () {
|
||||
_search.clear();
|
||||
setState(() {});
|
||||
},
|
||||
isUnseen: _controller.isUnseen,
|
||||
errorFor: _controller.errorFor,
|
||||
onDismissError: _controller.dismissError,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
// The web's hide report is a fixed overlay: replacing or
|
||||
// growing it must never move the list or overflow the screen.
|
||||
if (_controller.lastHidden != null)
|
||||
Positioned(
|
||||
left: 8,
|
||||
right: 8,
|
||||
bottom: 8,
|
||||
child: ChatUndoBar(
|
||||
key: const Key('chat-undo-hide'),
|
||||
message:
|
||||
'Hidden on this device; the chat stays on the server.',
|
||||
onUndo: _undoHide,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
// Under the shell, New chat and Refresh are its bar's actions; the
|
||||
@@ -291,7 +300,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
title: 'Chats',
|
||||
actions: _actions(),
|
||||
),
|
||||
child: SafeArea(child: body),
|
||||
// The list scrolls behind the bar, which does not fully obstruct;
|
||||
// it pads its first row by the bar's height itself.
|
||||
child: SafeArea(top: false, child: body),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
@@ -301,13 +312,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
title: 'Chats',
|
||||
actions: _actions(),
|
||||
),
|
||||
body: SafeArea(left: false, right: false, bottom: false, child: body),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
key: const Key('chat-new-chat-fab'),
|
||||
onPressed: _newChat,
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New chat'),
|
||||
),
|
||||
// The list scrolls behind the floating bar; New chat is the bar's
|
||||
// own action, so there is no second create button.
|
||||
body: body,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -48,9 +48,11 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
// Starts below a floating top bar (its height arrives as media top
|
||||
// padding) and ends clear of a floating bottom bar.
|
||||
padding: withFloatingBarClearance(
|
||||
context,
|
||||
const EdgeInsets.only(bottom: 24),
|
||||
EdgeInsets.only(top: MediaQuery.paddingOf(context).top, bottom: 24),
|
||||
),
|
||||
children: [
|
||||
for (final section in sections) ..._section(section),
|
||||
|
||||
Reference in New Issue
Block a user