fix(app): float the chat composer as glass, cap the reading width, tidy chat chrome

This commit is contained in:
2026-10-31 03:04:23 +00:00
parent ea0f22dfc7
commit 481b1f6fff
17 changed files with 805 additions and 368 deletions
@@ -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) {
final color = CupertinoColors.secondaryLabel.resolveFrom(context);
button = CupertinoButton(
key: const Key('chat-background-tasks-button'), key: const Key('chat-background-tasks-button'),
sizeStyle: CupertinoButtonSize.small, sizeStyle: CupertinoButtonSize.small,
padding: EdgeInsets.zero, padding: const EdgeInsets.symmetric(horizontal: 6),
onPressed: _open, onPressed: _open,
child: Text( 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,
child: Text(
label,
style: Theme.of(context).textTheme.labelSmall?.copyWith(
color: Theme.of(context).colorScheme.primary,
), ),
],
), ),
); );
return Semantics( } 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, button: true,
excludeSemantics: true, excludeSemantics: true,
onTap: _open, onTap: _open,
label: controller.error != null label: failed
? 'Background tasks unavailable' ? 'Background tasks unavailable'
: 'Background tasks, $label', : 'Background tasks, $label',
child: button, 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,24 +614,10 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
final selected = commands.isEmpty final selected = commands.isEmpty
? 0 ? 0
: _selectedCommand % commands.length; : _selectedCommand % commands.length;
return SafeArea( // Everything the next message carries (attachments, its notices) sits
top: false, // inside the glass with the field, as one floating composer; only the
child: Padding( // command palette, a separate menu, floats above it.
key: const Key('chat-composer'), final extras = <Widget>[
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 (!_attachments.isEmpty) _attachmentStrip(context, cupertino),
if (_uploading) if (_uploading)
_notice( _notice(
@@ -664,14 +652,52 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
text: error, text: error,
failed: true, failed: true,
), ),
if (widget.backgroundTasks != null) ];
Align( return SafeArea(
alignment: AlignmentDirectional.centerEnd, top: false,
child: widget.backgroundTasks!, // 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,
),
), ),
_pill( _pill(
context, context,
cupertino, 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( Row(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
@@ -684,6 +710,10 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
child: _field(cupertino), 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) ...[ if (widget.running) ...[
_primary(context, cupertino, stop: true), _primary(context, cupertino, stop: true),
const SizedBox(width: 4), const SizedBox(width: 4),
@@ -691,31 +721,30 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
_primary(context, cupertino), _primary(context, cupertino),
], ],
), ),
],
),
), ),
], ],
), ),
), ),
),
),
); );
}, },
); );
} }
/// 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
? CupertinoColors.systemGrey6.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
return DecoratedBox(
key: const Key('chat-composer-pill'), key: const Key('chat-composer-pill'),
decoration: BoxDecoration( cupertino: cupertino,
color: fill, shape: const RoundedRectangleBorder(
borderRadius: const BorderRadius.all(Radius.circular(28)), borderRadius: BorderRadius.all(Radius.circular(28)),
), ),
child: Padding(padding: const EdgeInsets.all(4), child: child), 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,29 +719,53 @@ 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(
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( child: SegmentedBarOverlay(
bar: _header(context, inShellBar), bar: _header(context, inShellBar),
child: NotificationListener<ScrollMetricsNotification>( child: NotificationListener<ScrollMetricsNotification>(
onNotification: _onScrollMetrics, onNotification: _onScrollMetrics,
child: NotificationListener<ScrollNotification>( child: NotificationListener<ScrollNotification>(
onNotification: _onScrollNotification, onNotification: _onScrollNotification,
child: Stack( 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, controller: _scroll,
padding: EdgeInsets.only( padding: EdgeInsets.fromLTRB(
top: MediaQuery.paddingOf(context).top + 8, side,
bottom: 8, media.top + 8,
side,
media.bottom + 8,
), ),
children: [ children: [
if (initialLoad) if (initialLoad)
@@ -830,11 +856,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
), ),
], ],
), ),
),
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,10 +913,17 @@ 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 || hasMode)
LayoutBuilder(
builder: (context, constraints) => Row(
mainAxisSize: MainAxisSize.min,
children: [
if (hasModel) if (hasModel)
ConstrainedBox( Flexible(
constraints: const BoxConstraints(maxWidth: 160),
child: ChatModelControl( child: ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'), key: ValueKey<String>('chat-model-${widget.sessionId}'),
gateway: widget.gateway, gateway: widget.gateway,
@@ -914,11 +933,21 @@ class _ChatThreadViewState extends State<ChatThreadView> {
answeredBy: latestReplyModel(_controller.messages), 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( ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 140), constraints: BoxConstraints(
maxWidth: hasModel
? constraints.maxWidth / 2
: constraints.maxWidth,
),
child: _modeControl(), child: _modeControl(),
), ),
], ],
),
),
],
); );
} }
@@ -193,15 +193,27 @@ 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.
final body = Builder(
builder: (context) => Column(
children: [ 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) if (_controller.error != null)
ChatErrorNotice( Padding(
padding: EdgeInsets.only(
top: MediaQuery.paddingOf(context).top,
),
child: ChatErrorNotice(
message: _controller.error!, message: _controller.error!,
onRetry: _controller.refresh, onRetry: _controller.refresh,
), ),
),
Expanded( Expanded(
child: MediaQuery.removePadding(
context: context,
removeTop: _controller.error != null,
child: Stack( child: Stack(
children: [ children: [
ContentWidth( ContentWidth(
@@ -232,16 +244,11 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
), ),
// The web's hide report is a fixed overlay: replacing or // The web's hide report is a fixed overlay: replacing or
// growing it must never move the list or overflow the screen. // 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) if (_controller.lastHidden != null)
Positioned( Positioned(
left: 8, left: 8,
right: 8, right: 8,
bottom: bottom: 8,
!widget.embedded &&
controls == ChatControlsStyle.material
? 88
: 8,
child: ChatUndoBar( child: ChatUndoBar(
key: const Key('chat-undo-hide'), key: const Key('chat-undo-hide'),
message: message:
@@ -252,7 +259,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
], ],
), ),
), ),
),
], ],
),
); );
// 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();
} }