Evenly space chat action bar controls

Add a uniform desktop gap between header control groups and remove duplicated horizontal padding from model and mode controls. Preserve compact-layout touch targets and add Material/Cupertino regression coverage.
This commit is contained in:
2026-11-10 16:38:55 +00:00
parent c6ab716ecb
commit 123c864397
6 changed files with 104 additions and 28 deletions
@@ -9,12 +9,16 @@ import 'chat_bar_tint.dart';
///
/// Material: a [TextButton] style in the role the bar's icon buttons use
/// (`onSurfaceVariant`).
ButtonStyle chatBarTextButtonStyle(BuildContext context) =>
TextButton.styleFrom(
foregroundColor:
ChatBarTintScope.foregroundOf(context) ??
Theme.of(context).colorScheme.onSurfaceVariant,
);
ButtonStyle chatBarTextButtonStyle(
BuildContext context, {
bool compact = false,
}) => TextButton.styleFrom(
foregroundColor:
ChatBarTintScope.foregroundOf(context) ??
Theme.of(context).colorScheme.onSurfaceVariant,
padding: compact ? null : EdgeInsets.zero,
minimumSize: compact ? null : const Size.square(kMinInteractiveDimension),
);
/// Cupertino: [content] (a [CupertinoButton]'s child) in the label colour
/// instead of the button's tint.
@@ -126,7 +126,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
child: ExcludeSemantics(
child: CupertinoButton(
key: key,
padding: const EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.zero,
onPressed: _open,
child: chatBarCupertinoContent(context, content),
),
@@ -143,7 +143,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
message: 'Change mode (currently $label)',
child: TextButton(
key: key,
style: chatBarTextButtonStyle(context),
style: chatBarTextButtonStyle(context, compact: iconOnly),
onPressed: _open,
child: content,
),
@@ -139,7 +139,7 @@ class _ChatModelControlState extends State<ChatModelControl> {
child: ExcludeSemantics(
child: CupertinoButton(
key: key,
padding: const EdgeInsets.symmetric(horizontal: 8),
padding: EdgeInsets.zero,
onPressed: _open,
child: chatBarCupertinoContent(context, content),
),
@@ -156,7 +156,7 @@ class _ChatModelControlState extends State<ChatModelControl> {
message: 'Change model (currently $label)',
child: TextButton(
key: key,
style: chatBarTextButtonStyle(context),
style: chatBarTextButtonStyle(context, compact: compact),
onPressed: _open,
child: content,
),
@@ -67,6 +67,20 @@ class ChatThreadHeader extends StatelessWidget {
builder: (context, constraints) {
final textScale = MediaQuery.textScalerOf(context).scale(14) / 14;
final compact = constraints.maxWidth / textScale < 800;
final actionChildren = [
...actions,
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
SegmentedMoreButton(
cupertino: cupertino,
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
],
),
];
final Widget bar = SegmentedBar(
cupertino: cupertino,
pillColor: tint?.fill,
@@ -96,6 +110,7 @@ class ChatThreadHeader extends StatelessWidget {
ChatWorkspacePaneActionBar(
child: _ControlIsland(
key: const Key('chat-model-permission-island'),
gap: compact ? 0 : 8,
children: controls,
),
),
@@ -105,22 +120,10 @@ class ChatThreadHeader extends StatelessWidget {
key: const Key('chat-actions-island'),
mainAxisSize: MainAxisSize.min,
children: [
...actions,
// Unknown action widgets retain their original behavior and stay
// visible; only the explicit overflow contract becomes a menu.
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions
.whereType<SegmentedOverflowable>()
.isNotEmpty)
SegmentedMoreButton(
cupertino: cupertino,
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
],
),
for (final (index, action) in actionChildren.indexed) ...[
if (index > 0 && !compact) const SizedBox(width: 8),
action,
],
],
),
),
@@ -148,12 +151,18 @@ class ChatThreadHeader extends StatelessWidget {
/// Related selectors share the available width. Each remains a real control;
/// they never migrate into the unrelated actions menu.
class _ControlIsland extends StatelessWidget {
const _ControlIsland({super.key, required this.children});
const _ControlIsland({super.key, required this.children, required this.gap});
final List<Widget> children;
final double gap;
@override
Widget build(BuildContext context) => Row(
mainAxisSize: MainAxisSize.min,
children: [for (final child in children) Flexible(child: child)],
children: [
for (final (index, child) in children.indexed) ...[
if (index > 0) SizedBox(width: gap),
Flexible(child: child),
],
],
);
}
@@ -0,0 +1,10 @@
# Even spacing between chat action bar controls
Implemented one explicit 8dp gap between controls within the model/mode group,
between action widgets, and between the two action groups. Removed duplicate
horizontal padding from chat model/mode text controls while retaining native
minimum touch targets.
Focused regression coverage is in
`test/features/chat/conversation/chat_thread_header_test.dart` for Material and
Cupertino at 1440x900. UI captures are owned by the UI review stage.
@@ -38,6 +38,59 @@ void _useNarrowText(WidgetTester tester) {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} wide header uses one explicit control gap',
(tester) async {
tester.view.physicalSize = const Size(1440, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
Widget control(String key) =>
SizedBox(key: Key(key), width: 48, height: 48);
await tester.pumpWidget(
_host(
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
controls: [
control('header-control-1'),
control('header-control-2'),
],
actions: [control('header-action-1'), control('header-action-2')],
moreActions: [
ChatBarAction(
label: 'More action',
onPressed: () {},
materialIcon: Icons.more_horiz,
cupertinoIcon: CupertinoIcons.ellipsis,
),
],
),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
double gap(String left, String right) =>
tester.getTopLeft(find.byKey(Key(right))).dx -
tester.getTopRight(find.byKey(Key(left))).dx;
expect(gap('header-control-1', 'header-control-2'), 8);
expect(gap('header-control-2', 'header-action-1'), 8);
expect(gap('header-action-1', 'header-action-2'), 8);
expect(
tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx -
tester.getTopRight(find.byKey(const Key('header-action-2'))).dx,
8,
);
},
);
}
testWidgets('short large-text header keeps controls in its single row', (
tester,
) async {