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_controller.dart';
|
||||||
import 'chat_background_tasks_panel.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 {
|
class ChatBackgroundTasks extends StatefulWidget {
|
||||||
const ChatBackgroundTasks({
|
const ChatBackgroundTasks({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -109,43 +110,63 @@ class _ChatBackgroundTasksState extends State<ChatBackgroundTasks> {
|
|||||||
listenable: controller,
|
listenable: controller,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
final count = controller.running.length;
|
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'
|
? 'Tasks'
|
||||||
: controller.loading && count == 0
|
|
||||||
? 'Tasks…'
|
|
||||||
: '$count ${count == 1 ? 'task' : 'tasks'}';
|
: '$count ${count == 1 ? 'task' : 'tasks'}';
|
||||||
final cupertino =
|
final cupertino =
|
||||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||||
final button = cupertino
|
final Widget button;
|
||||||
? CupertinoButton(
|
if (cupertino) {
|
||||||
key: const Key('chat-background-tasks-button'),
|
final color = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||||
sizeStyle: CupertinoButtonSize.small,
|
button = CupertinoButton(
|
||||||
padding: EdgeInsets.zero,
|
key: const Key('chat-background-tasks-button'),
|
||||||
onPressed: _open,
|
sizeStyle: CupertinoButtonSize.small,
|
||||||
child: Text(
|
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,
|
label,
|
||||||
style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle
|
style: CupertinoTheme.of(
|
||||||
.copyWith(color: CupertinoTheme.of(context).primaryColor),
|
context,
|
||||||
|
).textTheme.tabLabelTextStyle.copyWith(color: color),
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
: TextButton(
|
),
|
||||||
key: const Key('chat-background-tasks-button'),
|
);
|
||||||
onPressed: _open,
|
} else {
|
||||||
child: Text(
|
final theme = Theme.of(context);
|
||||||
label,
|
button = TextButton.icon(
|
||||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
key: const Key('chat-background-tasks-button'),
|
||||||
color: Theme.of(context).colorScheme.primary,
|
style: TextButton.styleFrom(
|
||||||
),
|
foregroundColor: theme.colorScheme.onSurfaceVariant,
|
||||||
),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
);
|
visualDensity: VisualDensity.compact,
|
||||||
return Semantics(
|
),
|
||||||
button: true,
|
onPressed: _open,
|
||||||
excludeSemantics: true,
|
icon: const Icon(Icons.layers_outlined, size: 16),
|
||||||
onTap: _open,
|
label: Text(label, style: theme.textTheme.labelSmall),
|
||||||
label: controller.error != null
|
);
|
||||||
? 'Background tasks unavailable'
|
}
|
||||||
: 'Background tasks, $label',
|
return Padding(
|
||||||
child: button,
|
// 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_command_palette.dart';
|
||||||
import 'chat_composer_controller.dart';
|
import 'chat_composer_controller.dart';
|
||||||
import '../ui/transcript/chat_attachment_frame.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.
|
/// The composer's placeholder when the chat names no working directory.
|
||||||
const String chatComposerPlaceholder = 'Message the agent';
|
const String chatComposerPlaceholder = 'Message the agent';
|
||||||
@@ -612,87 +614,119 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
|||||||
final selected = commands.isEmpty
|
final selected = commands.isEmpty
|
||||||
? 0
|
? 0
|
||||||
: _selectedCommand % commands.length;
|
: _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(
|
return SafeArea(
|
||||||
top: false,
|
top: false,
|
||||||
child: Padding(
|
// The composer floats over the transcript in the conversation's
|
||||||
key: const Key('chat-composer'),
|
// centred reading column; the space beside it passes taps through.
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 8),
|
child: Align(
|
||||||
child: Column(
|
heightFactor: 1,
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: ConstrainedBox(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
constraints: const BoxConstraints(maxWidth: kChatReadingWidth),
|
||||||
children: [
|
child: Padding(
|
||||||
if (commands.isNotEmpty)
|
key: const Key('chat-composer'),
|
||||||
Padding(
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 12),
|
||||||
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
child: Column(
|
||||||
child: ChatCommandPalette(
|
mainAxisSize: MainAxisSize.min,
|
||||||
commands: commands,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
selectedIndex: selected,
|
children: [
|
||||||
onSelected: _completeCommand,
|
if (commands.isNotEmpty)
|
||||||
),
|
Padding(
|
||||||
),
|
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
||||||
if (!_attachments.isEmpty) _attachmentStrip(context, cupertino),
|
child: ChatCommandPalette(
|
||||||
if (_uploading)
|
commands: commands,
|
||||||
_notice(
|
selectedIndex: selected,
|
||||||
context,
|
onSelected: _completeCommand,
|
||||||
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),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (widget.running) ...[
|
_pill(
|
||||||
_primary(context, cupertino, stop: true),
|
context,
|
||||||
const SizedBox(width: 4),
|
cupertino,
|
||||||
],
|
Column(
|
||||||
_primary(context, cupertino),
|
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
|
/// The field and its controls in one frosted-glass surface floating over
|
||||||
/// own fill role, so the composer reads as a single input rather than a row
|
/// the transcript, so the composer reads as a single input rather than a
|
||||||
/// of separate controls.
|
/// row of separate controls, and the conversation shows through it.
|
||||||
Widget _pill(BuildContext context, bool cupertino, Widget child) {
|
Widget _pill(BuildContext context, bool cupertino, Widget child) => GlassPill(
|
||||||
final fill = cupertino
|
key: const Key('chat-composer-pill'),
|
||||||
? CupertinoColors.systemGrey6.resolveFrom(context)
|
cupertino: cupertino,
|
||||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
shape: const RoundedRectangleBorder(
|
||||||
return DecoratedBox(
|
borderRadius: BorderRadius.all(Radius.circular(28)),
|
||||||
key: const Key('chat-composer-pill'),
|
),
|
||||||
decoration: BoxDecoration(
|
child: Padding(padding: const EdgeInsets.all(4), child: child),
|
||||||
color: fill,
|
);
|
||||||
borderRadius: const 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
|
/// 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.
|
/// 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 '../../../core/error_reason.dart';
|
||||||
import '../data/chat_repository.dart';
|
import '../data/chat_repository.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
|
import 'chat_bar_control_style.dart';
|
||||||
|
|
||||||
/// The conversation bar's permission-mode control.
|
/// The conversation bar's permission-mode control.
|
||||||
///
|
///
|
||||||
@@ -118,14 +119,19 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
|||||||
key: key,
|
key: key,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
onPressed: _open,
|
onPressed: _open,
|
||||||
child: content,
|
child: chatBarCupertinoContent(context, content),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Tooltip(
|
return Tooltip(
|
||||||
message: 'Change mode (currently $label)',
|
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 '../../../core/api_gateway.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
|
import 'chat_bar_control_style.dart';
|
||||||
import 'chat_model_chooser.dart';
|
import 'chat_model_chooser.dart';
|
||||||
import 'chat_models.dart';
|
import 'chat_models.dart';
|
||||||
|
|
||||||
@@ -135,14 +136,19 @@ class _ChatModelControlState extends State<ChatModelControl> {
|
|||||||
key: key,
|
key: key,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
onPressed: _open,
|
onPressed: _open,
|
||||||
child: content,
|
child: chatBarCupertinoContent(context, content),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Tooltip(
|
return Tooltip(
|
||||||
message: 'Change model (currently $label)',
|
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_row_keys.dart';
|
||||||
import 'chat_scroll.dart';
|
import 'chat_scroll.dart';
|
||||||
import 'chat_thread_controller.dart';
|
import 'chat_thread_controller.dart';
|
||||||
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||||
import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
||||||
|
import 'chat_reading_width.dart';
|
||||||
import 'chat_thread_header.dart';
|
import 'chat_thread_header.dart';
|
||||||
import 'chat_transcript_cache.dart';
|
import 'chat_transcript_cache.dart';
|
||||||
import 'chat_permission_card_model.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,
|
// Under the app shell the conversation takes over the app's bar (title,
|
||||||
// Back, model, information) instead of drawing a second bar below it.
|
// Back, model, information) instead of drawing a second bar below it.
|
||||||
final inShellBar = ShellBar.available(context);
|
final inShellBar = ShellBar.available(context);
|
||||||
final column = Column(
|
// The transcript fills the page; the conversation's bar floats over its
|
||||||
children: [
|
// top and the frosted composer over its bottom, and history scrolls
|
||||||
Expanded(
|
// behind both.
|
||||||
// The conversation's own bar floats over its transcript, which
|
final column = FloatingBarOverlay(
|
||||||
// scrolls behind it.
|
bar: ChatComposerBar(
|
||||||
child: SegmentedBarOverlay(
|
key: ValueKey<String>('chat-composer-${widget.sessionId}'),
|
||||||
bar: _header(context, inShellBar),
|
composer: _composer,
|
||||||
child: NotificationListener<ScrollMetricsNotification>(
|
running: _controller.running,
|
||||||
onNotification: _onScrollMetrics,
|
commands: _commandActions(),
|
||||||
child: NotificationListener<ScrollNotification>(
|
picker: widget.attachmentPicker,
|
||||||
onNotification: _onScrollNotification,
|
images: _images,
|
||||||
child: Stack(
|
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: [
|
children: [
|
||||||
Builder(
|
// At rest the first item starts below the floating bar
|
||||||
// At rest the first item starts below the floating bar.
|
// and the last one ends above the floating composer.
|
||||||
builder: (context) => ListView(
|
ListView(
|
||||||
key: ValueKey<String>(
|
key: ValueKey<String>(
|
||||||
'chat-thread-${widget.sessionId}',
|
'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,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
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)
|
if (showJump)
|
||||||
PositionedDirectional(
|
PositionedDirectional(
|
||||||
end: 16,
|
end: side + 16,
|
||||||
bottom: 16,
|
bottom: media.bottom + 16,
|
||||||
child: _ChatJumpToLatest(
|
child: _ChatJumpToLatest(
|
||||||
key: const Key('chat-jump-to-latest'),
|
key: const Key('chat-jump-to-latest'),
|
||||||
label: chatJumpToLatestLabel(newMessages),
|
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;
|
if (!inShellBar) return column;
|
||||||
// The conversation draws its own floating bar; the page shows none.
|
// 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 session = widget.session;
|
||||||
final hasModel =
|
final hasModel =
|
||||||
session != null && supportsChatModels('${session['backend'] ?? ''}');
|
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
|
final canGoBack = inShellBar
|
||||||
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
|
||||||
: true;
|
: true;
|
||||||
@@ -901,23 +913,40 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
|||||||
// A pushed page keeps the platform's stock Back (pop this route); a
|
// A pushed page keeps the platform's stock Back (pop this route); a
|
||||||
// standalone conversation calls its owner.
|
// standalone conversation calls its owner.
|
||||||
onBack: inShellBar ? null : widget.onBack,
|
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: [
|
controls: [
|
||||||
if (hasModel)
|
if (hasModel || hasMode)
|
||||||
ConstrainedBox(
|
LayoutBuilder(
|
||||||
constraints: const BoxConstraints(maxWidth: 160),
|
builder: (context, constraints) => Row(
|
||||||
child: ChatModelControl(
|
mainAxisSize: MainAxisSize.min,
|
||||||
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
children: [
|
||||||
gateway: widget.gateway,
|
if (hasModel)
|
||||||
sessionId: widget.sessionId,
|
Flexible(
|
||||||
session: session,
|
child: ChatModelControl(
|
||||||
onChanged: widget.onModelChanged,
|
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||||
answeredBy: latestReplyModel(_controller.messages),
|
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(
|
return ListenableBuilder(
|
||||||
listenable: _controller,
|
listenable: _controller,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
final controls = chatControlsStyleOf(context);
|
// Built under the page's scaffold, whose media padding carries the
|
||||||
final body = Column(
|
// floating bar's height.
|
||||||
children: [
|
final body = Builder(
|
||||||
if (_controller.error != null)
|
builder: (context) => Column(
|
||||||
ChatErrorNotice(
|
children: [
|
||||||
message: _controller.error!,
|
// A notice above the list starts below the floating bar; the list
|
||||||
onRetry: _controller.refresh,
|
// under it then needs no inset of its own.
|
||||||
),
|
if (_controller.error != null)
|
||||||
Expanded(
|
Padding(
|
||||||
child: Stack(
|
padding: EdgeInsets.only(
|
||||||
children: [
|
top: MediaQuery.paddingOf(context).top,
|
||||||
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
|
child: ChatErrorNotice(
|
||||||
// growing it must never move the list or overflow the screen.
|
message: _controller.error!,
|
||||||
// A standalone Material screen keeps it clear of the FAB.
|
onRetry: _controller.refresh,
|
||||||
if (_controller.lastHidden != null)
|
),
|
||||||
Positioned(
|
),
|
||||||
left: 8,
|
Expanded(
|
||||||
right: 8,
|
child: MediaQuery.removePadding(
|
||||||
bottom:
|
context: context,
|
||||||
!widget.embedded &&
|
removeTop: _controller.error != null,
|
||||||
controls == ChatControlsStyle.material
|
child: Stack(
|
||||||
? 88
|
children: [
|
||||||
: 8,
|
ContentWidth(
|
||||||
child: ChatUndoBar(
|
child: ChatSessionsBody(
|
||||||
key: const Key('chat-undo-hide'),
|
sessions: _controller.sessions,
|
||||||
message:
|
activeSessionId: widget.activeSessionId,
|
||||||
'Hidden on this device; the chat stays on the server.',
|
query: _search.text,
|
||||||
onUndo: _undoHide,
|
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
|
// Under the shell, New chat and Refresh are its bar's actions; the
|
||||||
@@ -291,7 +300,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
|||||||
title: 'Chats',
|
title: 'Chats',
|
||||||
actions: _actions(),
|
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(
|
return Scaffold(
|
||||||
@@ -301,13 +312,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
|||||||
title: 'Chats',
|
title: 'Chats',
|
||||||
actions: _actions(),
|
actions: _actions(),
|
||||||
),
|
),
|
||||||
body: SafeArea(left: false, right: false, bottom: false, child: body),
|
// The list scrolls behind the floating bar; New chat is the bar's
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
// own action, so there is no second create button.
|
||||||
key: const Key('chat-new-chat-fab'),
|
body: body,
|
||||||
onPressed: _newChat,
|
|
||||||
icon: const Icon(Icons.add),
|
|
||||||
label: const Text('New chat'),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,9 +48,11 @@ class CupertinoSessionList extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView(
|
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(
|
padding: withFloatingBarClearance(
|
||||||
context,
|
context,
|
||||||
const EdgeInsets.only(bottom: 24),
|
EdgeInsets.only(top: MediaQuery.paddingOf(context).top, bottom: 24),
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
for (final section in sections) ..._section(section),
|
for (final section in sections) ..._section(section),
|
||||||
|
|||||||
@@ -94,7 +94,12 @@ void main() {
|
|||||||
find.byKey(const Key('chat-background-tasks-modal')),
|
find.byKey(const Key('chat-background-tasks-modal')),
|
||||||
findsNothing,
|
findsNothing,
|
||||||
);
|
);
|
||||||
expect(find.text('0 tasks'), findsOneWidget);
|
// The other session runs nothing: no control, never a "0 tasks".
|
||||||
|
expect(find.text('0 tasks'), findsNothing);
|
||||||
|
expect(
|
||||||
|
find.byKey(const Key('chat-background-tasks-button')),
|
||||||
|
findsNothing,
|
||||||
|
);
|
||||||
expect(find.text('old session output'), findsNothing);
|
expect(find.text('old session output'), findsNothing);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
},
|
},
|
||||||
@@ -104,7 +109,10 @@ void main() {
|
|||||||
testWidgets(
|
testWidgets(
|
||||||
'owner disposal removes only its modal, not an unrelated top route',
|
'owner disposal removes only its modal, not an unrelated top route',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final gateway = TasksGateway();
|
final gateway = TasksGateway()
|
||||||
|
..shells = (_) async => {
|
||||||
|
'chat_shells': [task('a')],
|
||||||
|
};
|
||||||
addTearDown(gateway.close);
|
addTearDown(gateway.close);
|
||||||
var visible = true;
|
var visible = true;
|
||||||
late StateSetter rebuild;
|
late StateSetter rebuild;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void main() {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('an empty snapshot shows zero tasks and an honest empty modal', (
|
testWidgets('an empty snapshot shows no task control, never "0 tasks"', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
final gateway = _TasksGateway();
|
final gateway = _TasksGateway();
|
||||||
@@ -165,11 +165,10 @@ void main() {
|
|||||||
await tester.pumpWidget(_host(gateway));
|
await tester.pumpWidget(_host(gateway));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('0 tasks'), findsOneWidget);
|
expect(find.text('0 tasks'), findsNothing);
|
||||||
expect(find.text('Background tasks'), findsNothing);
|
expect(find.textContaining('task'), findsNothing);
|
||||||
|
expect(find.byKey(const Key('chat-background-tasks-button')), findsNothing);
|
||||||
expect(gateway.fieldsFor('chat_shells'), hasLength(1));
|
expect(gateway.fieldsFor('chat_shells'), hasLength(1));
|
||||||
await _openTasks(tester);
|
|
||||||
expect(find.text('No background tasks running.'), findsOneWidget);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('pushed shell frames add and remove this session tasks', (
|
testWidgets('pushed shell frames add and remove this session tasks', (
|
||||||
@@ -612,7 +611,7 @@ void main() {
|
|||||||
expect(find.text('go test ./...'), findsNothing);
|
expect(find.text('go test ./...'), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('the task badge sits above Send, outside the transcript', (
|
testWidgets('the task control sits inside the composer pill beside Send', (
|
||||||
tester,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
final gateway = _TasksGateway();
|
final gateway = _TasksGateway();
|
||||||
@@ -622,19 +621,39 @@ void main() {
|
|||||||
await tester.pumpWidget(_thread(gateway));
|
await tester.pumpWidget(_thread(gateway));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
final tasks = tester.getRect(
|
final button = find.byKey(const Key('chat-background-tasks-button'));
|
||||||
find.byKey(const Key('chat-background-tasks-button')),
|
expect(
|
||||||
);
|
find.descendant(
|
||||||
final list = tester.getRect(
|
of: find.byKey(const Key('chat-composer-pill')),
|
||||||
find.byKey(const ValueKey<String>('chat-thread-s')),
|
matching: button,
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
|
final tasks = tester.getRect(button);
|
||||||
final send = tester.getRect(find.byKey(const Key('chat-composer-primary')));
|
final send = tester.getRect(find.byKey(const Key('chat-composer-primary')));
|
||||||
final composer = tester.getRect(
|
expect(tasks.right, lessThanOrEqualTo(send.left));
|
||||||
find.byKey(const ValueKey('chat-composer-s')),
|
expect(tasks.bottom, greaterThan(send.top));
|
||||||
|
expect(tasks.top, lessThan(send.bottom));
|
||||||
|
// Neutral, not the primary tint.
|
||||||
|
final style = tester.widget<TextButton>(button).style!;
|
||||||
|
final theme = Theme.of(tester.element(button));
|
||||||
|
expect(
|
||||||
|
style.foregroundColor!.resolve({}),
|
||||||
|
theme.colorScheme.onSurfaceVariant,
|
||||||
);
|
);
|
||||||
expect(tasks.bottom, lessThanOrEqualTo(send.top));
|
});
|
||||||
expect(send.center.dx, inInclusiveRange(tasks.left, tasks.right));
|
|
||||||
expect(tasks.top, greaterThanOrEqualTo(composer.top));
|
testWidgets('a conversation without tasks shows no task caption', (
|
||||||
expect(list.bottom, lessThanOrEqualTo(composer.top));
|
tester,
|
||||||
|
) async {
|
||||||
|
final gateway = _TasksGateway();
|
||||||
|
addTearDown(gateway.close);
|
||||||
|
|
||||||
|
await tester.pumpWidget(_thread(gateway));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('0 tasks'), findsNothing);
|
||||||
|
expect(find.byKey(const Key('chat-background-tasks-button')), findsNothing);
|
||||||
|
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,210 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/conversation/chat_reading_width.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
|
||||||
|
|
||||||
|
import 'chat_thread_fixtures.dart';
|
||||||
|
|
||||||
|
/// Floating composer, reading width and header controls of a conversation.
|
||||||
|
|
||||||
|
Widget _host(Widget child, {required bool cupertino}) => cupertino
|
||||||
|
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||||
|
: MaterialApp(
|
||||||
|
theme: ThemeData(platform: TargetPlatform.android),
|
||||||
|
home: Scaffold(body: child),
|
||||||
|
);
|
||||||
|
|
||||||
|
void _size(WidgetTester tester, Size size) {
|
||||||
|
tester.view.physicalSize = size;
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, dynamic>> _messages(int count) => [
|
||||||
|
for (var index = 0; index < count; index++)
|
||||||
|
chatMessage(
|
||||||
|
'm$index',
|
||||||
|
index.isEven ? 'user' : 'assistant',
|
||||||
|
parts: [
|
||||||
|
{'type': 'text', 'text': 'Message number $index of the transcript.'},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
Future<FakeChatGateway> _pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required bool cupertino,
|
||||||
|
int messages = 30,
|
||||||
|
Map<String, dynamic>? session,
|
||||||
|
}) async {
|
||||||
|
final gateway = FakeChatGateway();
|
||||||
|
addTearDown(gateway.close);
|
||||||
|
gateway.history = (_) async => chatPage(_messages(messages));
|
||||||
|
gateway.subscribe = () async => const {};
|
||||||
|
await tester.pumpWidget(
|
||||||
|
_host(
|
||||||
|
ChatThreadView(
|
||||||
|
gateway: gateway,
|
||||||
|
sessionId: 's',
|
||||||
|
title: 'Floating chrome',
|
||||||
|
session: session,
|
||||||
|
onBack: () {},
|
||||||
|
),
|
||||||
|
cupertino: cupertino,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
return gateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for (final cupertino in [false, true]) {
|
||||||
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
|
||||||
|
testWidgets('$host composer floats as glass with the transcript behind', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
_size(tester, const Size(560, 800));
|
||||||
|
await _pump(tester, cupertino: cupertino);
|
||||||
|
|
||||||
|
final pill = find.byKey(const Key('chat-composer-pill'));
|
||||||
|
expect(tester.widget(pill), isA<GlassPill>());
|
||||||
|
// The transcript fills the page: it runs under the composer.
|
||||||
|
final list = tester.getRect(find.byKey(const ValueKey('chat-thread-s')));
|
||||||
|
final composer = tester.getRect(pill);
|
||||||
|
expect(list.bottom, 800);
|
||||||
|
expect(composer.bottom, lessThanOrEqualTo(800));
|
||||||
|
expect(composer.top, greaterThan(list.top));
|
||||||
|
expect(list.bottom, greaterThanOrEqualTo(composer.bottom));
|
||||||
|
|
||||||
|
// Following the end, the last message rests fully above the composer.
|
||||||
|
final last = tester.getRect(
|
||||||
|
find.text('Message number 29 of the transcript.'),
|
||||||
|
);
|
||||||
|
expect(last.bottom, lessThanOrEqualTo(composer.top));
|
||||||
|
|
||||||
|
// Scrolling back up passes history behind the floating composer.
|
||||||
|
await tester.drag(
|
||||||
|
find.byKey(const ValueKey('chat-thread-s')),
|
||||||
|
const Offset(0, 120),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final behind = find.text('Message number 29 of the transcript.');
|
||||||
|
if (behind.evaluate().isNotEmpty) {
|
||||||
|
expect(tester.getRect(behind).top, greaterThan(last.top));
|
||||||
|
}
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host transcript and composer share a centred reading width', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
_size(tester, const Size(1200, 800));
|
||||||
|
await _pump(tester, cupertino: cupertino, messages: 4);
|
||||||
|
|
||||||
|
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
|
||||||
|
expect(pill.width, lessThanOrEqualTo(kChatReadingWidth));
|
||||||
|
expect(pill.center.dx, closeTo(600, 1));
|
||||||
|
final message = tester.getRect(
|
||||||
|
find.text('Message number 0 of the transcript.'),
|
||||||
|
);
|
||||||
|
final inset = chatReadingInset(1200);
|
||||||
|
expect(message.left, greaterThanOrEqualTo(inset));
|
||||||
|
expect(message.right, lessThanOrEqualTo(1200 - inset));
|
||||||
|
// The list itself still spans the window, so its margins scroll it.
|
||||||
|
expect(
|
||||||
|
tester.getRect(find.byKey(const ValueKey('chat-thread-s'))).width,
|
||||||
|
1200,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Narrow, the column fills the width less the usual margins.
|
||||||
|
_size(tester, const Size(560, 800));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
tester.getRect(find.byKey(const Key('chat-composer-pill'))).width,
|
||||||
|
560 - 32,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host header draws no empty pill without model or mode', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
_size(tester, const Size(560, 800));
|
||||||
|
await _pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
messages: 1,
|
||||||
|
session: const {'id': 's', 'backend': 'pi', 'directory': '/srv'},
|
||||||
|
);
|
||||||
|
final header = find.byKey(const Key('chat-thread-header'));
|
||||||
|
expect(find.byKey(const Key('chat-mode')), findsNothing);
|
||||||
|
// Only the round Back and the title pill: no (empty) actions pill.
|
||||||
|
expect(
|
||||||
|
find.descendant(of: header, matching: find.byType(SegmentedPill)),
|
||||||
|
findsNWidgets(2),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('$host header controls keep their natural width when wide', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
_size(tester, const Size(1200, 800));
|
||||||
|
await _pump(
|
||||||
|
tester,
|
||||||
|
cupertino: cupertino,
|
||||||
|
messages: 1,
|
||||||
|
session: const {
|
||||||
|
'id': 's',
|
||||||
|
'backend': 'opencode',
|
||||||
|
'model': 'p/sonnet-4-5',
|
||||||
|
'mode': 'default',
|
||||||
|
'mode_name': 'Ask for permission',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final mode = find.byKey(const Key('chat-mode'));
|
||||||
|
final model = find.byKey(const Key('chat-model'));
|
||||||
|
expect(mode, findsOneWidget);
|
||||||
|
expect(model, findsOneWidget);
|
||||||
|
for (final control in [mode, model]) {
|
||||||
|
final texts = find.descendant(of: control, matching: find.byType(Text));
|
||||||
|
for (final element in texts.evaluate()) {
|
||||||
|
final paragraph = element.renderObject! as RenderParagraph;
|
||||||
|
expect(
|
||||||
|
paragraph.didExceedMaxLines,
|
||||||
|
isFalse,
|
||||||
|
reason: 'truncated at 1200',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Neutral like the bar's other actions, not the primary tint.
|
||||||
|
if (!cupertino) {
|
||||||
|
final button = tester.widget<TextButton>(mode);
|
||||||
|
final theme = Theme.of(tester.element(mode));
|
||||||
|
expect(
|
||||||
|
button.style!.foregroundColor!.resolve({}),
|
||||||
|
theme.colorScheme.onSurfaceVariant,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final label = tester.widget<RichText>(
|
||||||
|
find.descendant(
|
||||||
|
of: mode,
|
||||||
|
matching: find.byWidgetPredicate(
|
||||||
|
(widget) =>
|
||||||
|
widget is RichText &&
|
||||||
|
widget.text.toPlainText() == 'Ask for permission',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
label.text.style?.color,
|
||||||
|
CupertinoColors.label.resolveFrom(tester.element(mode)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ void main() {
|
|||||||
onOpen: (session) => opened = session,
|
onOpen: (session) => opened = session,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump(const Duration(milliseconds: 400));
|
await tester.pump(const Duration(milliseconds: 400));
|
||||||
expect(find.text('Loading directories…'), findsOneWidget);
|
expect(find.text('Loading directories…'), findsOneWidget);
|
||||||
@@ -115,7 +115,7 @@ void main() {
|
|||||||
gateway.directoriesHandler = () async => {'chat_directories': []};
|
gateway.directoriesHandler = () async => {'chat_directories': []};
|
||||||
await pumpMaterialChat(tester, gateway);
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.text('Home (~) — ~'), findsOneWidget);
|
expect(find.text('Home (~) — ~'), findsOneWidget);
|
||||||
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
||||||
@@ -210,7 +210,7 @@ void main() {
|
|||||||
|
|
||||||
final refresh = Completer<JsonMap>();
|
final refresh = Completer<JsonMap>();
|
||||||
gateway.pendingSessions.add(refresh);
|
gateway.pendingSessions.add(refresh);
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void main() {
|
|||||||
};
|
};
|
||||||
await pumpMaterialChat(tester, gateway);
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
await tester.ensureVisible(find.byKey(const Key('chat-create-send-prompt')));
|
await tester.ensureVisible(find.byKey(const Key('chat-create-send-prompt')));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void main() {
|
|||||||
onOpen: (session) => opened = session,
|
onOpen: (session) => opened = session,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
|
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -63,7 +63,7 @@ void main() {
|
|||||||
gateway.createHandler = (_) => reply.future;
|
gateway.createHandler = (_) => reply.future;
|
||||||
await pumpMaterialChat(tester, gateway);
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
await tester.tap(find.byKey(const Key('chat-create-confirm')));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
@@ -196,7 +196,7 @@ void main() {
|
|||||||
final gateway = FakeChatGateway()..createReply = const {};
|
final gateway = FakeChatGateway()..createReply = const {};
|
||||||
await pumpMaterialChat(tester, gateway);
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('chat-new-chat-fab')));
|
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
|
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||||
|
|
||||||
|
import 'chat_test_harness.dart';
|
||||||
|
import 'fake_chat_gateway.dart';
|
||||||
|
|
||||||
|
/// The standalone chat list scrolls behind its floating bar and creates chats
|
||||||
|
/// from the bar's one New chat action.
|
||||||
|
|
||||||
|
List<JsonMap> _many() => [
|
||||||
|
for (var index = 0; index < 30; index++)
|
||||||
|
{'id': 's$index', 'title': 'Chat $index', 'directory': '/work'},
|
||||||
|
];
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for (final cupertino in [false, true]) {
|
||||||
|
final host = cupertino ? 'Cupertino' : 'Material';
|
||||||
|
|
||||||
|
testWidgets('$host list scrolls behind the bar and starts below it', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final gateway = FakeChatGateway()
|
||||||
|
..sessionsReply = {'chat_sessions': _many()};
|
||||||
|
if (cupertino) {
|
||||||
|
await pumpCupertinoChat(tester, gateway);
|
||||||
|
} else {
|
||||||
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
}
|
||||||
|
|
||||||
|
final bar = tester.getRect(find.byType(SegmentedBar));
|
||||||
|
final list = tester.getRect(find.byType(ListView).first);
|
||||||
|
// The list reaches under the bar ...
|
||||||
|
expect(list.top, lessThan(bar.bottom));
|
||||||
|
// ... yet at rest its first row is clear of it.
|
||||||
|
final first = tester.getRect(
|
||||||
|
find.byKey(const ValueKey('chat-section-Chats')),
|
||||||
|
);
|
||||||
|
expect(first.top, greaterThanOrEqualTo(bar.bottom));
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('the standalone Material list has one New chat, in the bar', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final gateway = FakeChatGateway()
|
||||||
|
..sessionsReply = {'chat_sessions': _many()};
|
||||||
|
await pumpMaterialChat(tester, gateway);
|
||||||
|
|
||||||
|
expect(find.byType(FloatingActionButton), findsNothing);
|
||||||
|
expect(find.byKey(const Key('chat-new-chat-fab')), findsNothing);
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byType(SegmentedBar),
|
||||||
|
matching: find.byKey(const Key('chat-new-chat')),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -12,7 +12,10 @@ Future<void> expandClosedChats(WidgetTester tester) async {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
final heading = find.descendant(of: section, matching: find.text('Closed'));
|
final heading = find.descendant(of: section, matching: find.text('Closed'));
|
||||||
await tester.ensureVisible(heading.first);
|
// Centred rather than at the top edge: the list scrolls behind a floating
|
||||||
|
// bar, which would take a tap at the edge.
|
||||||
|
await Scrollable.ensureVisible(tester.element(heading.first), alignment: 0.5);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(heading.first);
|
await tester.tap(heading.first);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user