merge(app): land chat toolbar

This commit is contained in:
2026-10-23 13:11:13 +01:00
3 changed files with 117 additions and 35 deletions
@@ -52,38 +52,81 @@ class ChatBarAction extends StatelessWidget {
}
}
/// The chat toolbar's one primary create action, labelled as on the web
/// (`+ New chat`), not an unlabelled glyph.
class ChatNewChatButton extends StatelessWidget {
const ChatNewChatButton({super.key, required this.onPressed});
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoButton.filled(
sizeStyle: CupertinoButtonSize.small,
onPressed: onPressed,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(CupertinoIcons.add, size: 16),
SizedBox(width: 4),
Text('New chat'),
],
),
);
}
return FilledButton.icon(
onPressed: onPressed,
icon: const Icon(Icons.add),
label: const Text('New chat'),
);
}
}
class ChatSearchField extends StatelessWidget {
const ChatSearchField({
super.key,
required this.controller,
required this.onChanged,
this.trailing = const [],
});
final TextEditingController controller;
final ValueChanged<String> onChanged;
/// Actions on the search row's trailing edge, as the web's chat toolbar
/// keeps New chat beside its search input.
final List<Widget> trailing;
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return Padding(
padding: const EdgeInsets.all(16),
child: CupertinoSearchTextField(
controller: controller,
placeholder: 'Search chats',
onChanged: onChanged,
),
);
}
final field = chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoSearchTextField(
controller: controller,
placeholder: 'Search chats',
onChanged: onChanged,
)
: TextField(
controller: controller,
onChanged: onChanged,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
labelText: 'Search chats',
),
);
return Padding(
padding: const EdgeInsets.all(16),
child: TextField(
controller: controller,
onChanged: onChanged,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
labelText: 'Search chats',
),
),
child: trailing.isEmpty
? field
: Row(
children: [
Expanded(child: field),
for (final action in trailing) ...[
const SizedBox(width: 8),
action,
],
],
),
);
}
}
@@ -190,6 +190,23 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
ChatSearchField(
controller: _search,
onChanged: (_) => setState(() {}),
// Embedded under the shell there is no bar of its own: the
// create action sits beside search, as the web's chat toolbar.
trailing: widget.embedded
? [
ChatNewChatButton(
key: const Key('chat-new-chat'),
onPressed: _newChat,
),
ChatBarAction(
key: const Key('chat-refresh'),
label: 'Refresh',
onPressed: _controller.refresh,
materialIcon: Icons.refresh,
cupertinoIcon: CupertinoIcons.refresh,
),
]
: const [],
),
if (_controller.error != null)
ChatErrorNotice(
@@ -247,23 +264,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
],
);
if (widget.embedded) {
return Column(
children: [
Align(
alignment: AlignmentDirectional.centerEnd,
child: Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: _actions(),
),
),
),
Expanded(child: body),
],
);
}
if (widget.embedded) return body;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoPageScaffold(
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
void main() {
testWidgets('embedded, New chat sits beside search on one toolbar row', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(
body: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
embedded: true,
localStore: MemoryChatSessionLocalStore(),
),
),
),
);
await tester.pumpAndSettle();
final search = tester.getCenter(find.byType(TextField));
final create = find.byKey(const Key('chat-new-chat'));
expect(
find.descendant(of: create, matching: find.text('New chat')),
findsOneWidget,
);
expect((tester.getCenter(create).dy - search.dy).abs(), lessThan(4));
expect(tester.getCenter(create).dx, greaterThan(search.dx));
});
}