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:
@@ -84,6 +84,14 @@ ChatBarTint? chatBarTintOf(BuildContext context, String? name) {
|
|||||||
|
|
||||||
/// The composer's focus ring: the seeded scheme's `primary` for a coloured
|
/// 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.
|
/// 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) {
|
Color chatFocusRingColor(BuildContext context, String? name) {
|
||||||
final shade = chatColorShade(context, name);
|
final shade = chatColorShade(context, name);
|
||||||
if (shade != null) {
|
if (shade != null) {
|
||||||
@@ -105,7 +113,9 @@ class ChatPaneActivity extends InheritedWidget {
|
|||||||
final bool inactive;
|
final bool inactive;
|
||||||
|
|
||||||
static bool inactiveOf(BuildContext context) =>
|
static bool inactiveOf(BuildContext context) =>
|
||||||
context.dependOnInheritedWidgetOfExactType<ChatPaneActivity>()?.inactive ??
|
context
|
||||||
|
.dependOnInheritedWidgetOfExactType<ChatPaneActivity>()
|
||||||
|
?.inactive ??
|
||||||
false;
|
false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -148,6 +158,5 @@ class ChatBarTintScope extends InheritedWidget {
|
|||||||
.foreground;
|
.foreground;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(ChatBarTintScope oldWidget) =>
|
bool updateShouldNotify(ChatBarTintScope oldWidget) => tint != oldWidget.tint;
|
||||||
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
|
/// 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.
|
||||||
Widget _attach(BuildContext context, bool cupertino) {
|
Widget _attach(BuildContext context, bool cupertino) {
|
||||||
@@ -1335,6 +1334,9 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
|||||||
? chatRunShellLabel
|
? chatRunShellLabel
|
||||||
: chatSendLabel;
|
: chatSendLabel;
|
||||||
final key = Key(stop ? 'chat-composer-stop' : 'chat-composer-primary');
|
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) {
|
if (cupertino) {
|
||||||
return Semantics(
|
return Semantics(
|
||||||
button: true,
|
button: true,
|
||||||
@@ -1355,13 +1357,17 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
|||||||
),
|
),
|
||||||
color: stop
|
color: stop
|
||||||
? CupertinoColors.systemRed.resolveFrom(context)
|
? CupertinoColors.systemRed.resolveFrom(context)
|
||||||
: null,
|
: tinted?.primary,
|
||||||
onPressed: enabled ? press : null,
|
onPressed: enabled ? press : null,
|
||||||
child: stop
|
child: stop
|
||||||
? const ChatStopIcon(
|
? const ChatStopIcon(
|
||||||
child: Icon(CupertinoIcons.stop_fill, size: 18),
|
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,
|
backgroundColor: scheme.error,
|
||||||
foregroundColor: scheme.onError,
|
foregroundColor: scheme.onError,
|
||||||
)
|
)
|
||||||
: null,
|
: tinted == null
|
||||||
|
? null
|
||||||
|
: IconButton.styleFrom(
|
||||||
|
backgroundColor: tinted.primary,
|
||||||
|
foregroundColor: tinted.onPrimary,
|
||||||
|
),
|
||||||
onPressed: enabled ? press : null,
|
onPressed: enabled ? press : null,
|
||||||
icon: stop
|
icon: stop
|
||||||
? const ChatStopIcon(child: Icon(Icons.stop))
|
? const ChatStopIcon(child: Icon(Icons.stop))
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await _focusField(tester);
|
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 teal = chatColorShade(context, 'teal')!;
|
||||||
final expected = chatSeededScheme(teal, dark: false).primary;
|
final expected = chatSeededScheme(teal, dark: false).primary;
|
||||||
expect(_ring(tester).side.color, expected);
|
expect(_ring(tester).side.color, expected);
|
||||||
@@ -77,6 +79,35 @@ void main() {
|
|||||||
expect(expected, isNot(teal));
|
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 {
|
testWidgets('the ring fades out again when focus leaves', (tester) async {
|
||||||
await tester.pumpWidget(composerThread(gateway));
|
await tester.pumpWidget(composerThread(gateway));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|||||||
Reference in New Issue
Block a user