Colour the send button with the chat colour

A coloured chat's send button uses the chat's seeded primary and its
on-colour, like the focus ring; stop stays the host's error red and
uncoloured chats keep the host button.
This commit is contained in:
2026-11-10 02:33:14 +00:00
parent 87519985bf
commit 60b4c495f1
3 changed files with 59 additions and 8 deletions
@@ -84,6 +84,14 @@ ChatBarTint? chatBarTintOf(BuildContext context, String? name) {
/// The composer's focus ring: the seeded scheme's `primary` for a coloured
/// chat, else the host's primary colour; always drawn at full opacity.
/// The seeded scheme of a coloured chat in this context, or null for a chat
/// with no colour (which keeps the host's own controls).
ColorScheme? chatSchemeOf(BuildContext context, String? name) {
final shade = chatColorShade(context, name);
if (shade == null) return null;
return chatSeededScheme(shade, dark: chatColorDarkSurface(context));
}
Color chatFocusRingColor(BuildContext context, String? name) {
final shade = chatColorShade(context, name);
if (shade != null) {
@@ -105,7 +113,9 @@ class ChatPaneActivity extends InheritedWidget {
final bool inactive;
static bool inactiveOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ChatPaneActivity>()?.inactive ??
context
.dependOnInheritedWidgetOfExactType<ChatPaneActivity>()
?.inactive ??
false;
@override
@@ -148,6 +158,5 @@ class ChatBarTintScope extends InheritedWidget {
.foreground;
@override
bool updateShouldNotify(ChatBarTintScope oldWidget) =>
tint != oldWidget.tint;
bool updateShouldNotify(ChatBarTintScope oldWidget) => tint != oldWidget.tint;
}
@@ -983,7 +983,6 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
),
);
/// 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.
Widget _attach(BuildContext context, bool cupertino) {
@@ -1335,6 +1334,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
? chatRunShellLabel
: chatSendLabel;
final key = Key(stop ? 'chat-composer-stop' : 'chat-composer-primary');
// A coloured chat's send button takes the chat's colour (its seeded
// primary, like the focus ring); stop stays the host's error red.
final tinted = chatSchemeOf(context, widget.chatColor);
if (cupertino) {
return Semantics(
button: true,
@@ -1355,13 +1357,17 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
),
color: stop
? CupertinoColors.systemRed.resolveFrom(context)
: null,
: tinted?.primary,
onPressed: enabled ? press : null,
child: stop
? const ChatStopIcon(
child: Icon(CupertinoIcons.stop_fill, size: 18),
)
: const Icon(CupertinoIcons.arrow_up, size: 18),
: Icon(
CupertinoIcons.arrow_up,
size: 18,
color: enabled ? tinted?.onPrimary : null,
),
),
),
),
@@ -1376,7 +1382,12 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
backgroundColor: scheme.error,
foregroundColor: scheme.onError,
)
: null,
: tinted == null
? null
: IconButton.styleFrom(
backgroundColor: tinted.primary,
foregroundColor: tinted.onPrimary,
),
onPressed: enabled ? press : null,
icon: stop
? const ChatStopIcon(child: Icon(Icons.stop))
@@ -68,7 +68,9 @@ void main() {
await tester.pumpAndSettle();
await _focusField(tester);
final context = tester.element(find.byKey(const Key('chat-composer-field')));
final context = tester.element(
find.byKey(const Key('chat-composer-field')),
);
final teal = chatColorShade(context, 'teal')!;
final expected = chatSeededScheme(teal, dark: false).primary;
expect(_ring(tester).side.color, expected);
@@ -77,6 +79,35 @@ void main() {
expect(expected, isNot(teal));
});
testWidgets('a coloured chat\'s send button takes the chat colour', (
tester,
) async {
await tester.pumpWidget(
composerThread(gateway, session: {'id': 's', 'color': 'teal'}),
);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'hello',
);
await tester.pumpAndSettle();
final send = find.byKey(const Key('chat-composer-primary'));
final context = tester.element(send);
final scheme = chatSchemeOf(context, 'teal')!;
final button = tester.widget<IconButton>(send);
final states = <WidgetState>{};
expect(button.style!.backgroundColor!.resolve(states), scheme.primary);
expect(button.style!.foregroundColor!.resolve(states), scheme.onPrimary);
});
testWidgets('an uncoloured chat keeps the host send button', (tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
final send = find.byKey(const Key('chat-composer-primary'));
expect(tester.widget<IconButton>(send).style, isNull);
expect(chatSchemeOf(tester.element(send), null), isNull);
});
testWidgets('the ring fades out again when focus leaves', (tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();