Wash the operator's bubbles softly in the chat colour

A coloured chat's own messages blend 22% of its shade over the host's
neutral bubble fill; text keeps the host colours and uncoloured chats
are unchanged.
This commit is contained in:
2026-11-10 11:27:29 +00:00
parent 4ae2de444e
commit 19aa726e7f
3 changed files with 500 additions and 335 deletions
@@ -1,7 +1,34 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// The operator's turn: a neutral filled, evenly rounded bubble with no border,
import '../sessions/chat_color_palette.dart';
/// How strongly a coloured chat's shade washes the operator's bubbles over
/// the host's neutral bubble fill. Text keeps the host's colours.
const double chatBubbleTint = 0.22;
/// The open chat's colour name for the operator's bubbles below it; a chat
/// with no colour (or no scope) keeps the host's neutral bubble.
class ChatBubbleColor extends InheritedWidget {
const ChatBubbleColor({super.key, required this.name, required super.child});
final String? name;
static String? of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ChatBubbleColor>()?.name;
@override
bool updateShouldNotify(ChatBubbleColor old) => old.name != name;
}
/// [base] washed with the open chat's shade, or [base] for an uncoloured chat.
Color chatBubbleFill(BuildContext context, Color base) {
final shade = chatColorShade(context, ChatBubbleColor.of(context));
if (shade == null) return base;
return Color.alphaBlend(shade.withValues(alpha: chatBubbleTint), base);
}
/// The operator's turn: a filled (neutral, or softly in the chat's colour), evenly rounded bubble with no border,
/// in the host's own surface roles. The agent's turn has no bubble at all; its
/// text sits on the page, so only the operator's words are enclosed.
class ChatUserBubble extends StatelessWidget {
@@ -25,7 +52,10 @@ class ChatUserBubble extends StatelessWidget {
if (cupertino) {
return DecoratedBox(
decoration: BoxDecoration(
color: CupertinoColors.systemGrey5.resolveFrom(context),
color: chatBubbleFill(
context,
CupertinoColors.systemGrey5.resolveFrom(context),
),
borderRadius: _radius,
),
child: Padding(padding: _padding, child: child),
@@ -34,7 +64,10 @@ class ChatUserBubble extends StatelessWidget {
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
// inside the bubble keeps its ink and background.
return Material(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
color: chatBubbleFill(
context,
Theme.of(context).colorScheme.surfaceContainerHighest,
),
clipBehavior: Clip.antiAlias,
shape: const RoundedRectangleBorder(borderRadius: _radius),
child: Padding(padding: _padding, child: child),