ChatColors class
Customisation surface for the chat's visual palette.
widget_chat is sold to many tenants — each one wants the chat
surface to match their brand without forking the SDK. Rather than
piling color fields onto BotConfiguration (host plumbing per
session) or hardcoding them on every widget, we expose them as a
Flutter ThemeExtension: hosts attach an instance to their
MaterialApp.theme.extensions and every chat widget reads from it.
Every field is nullable. A null field falls back to a derived value from the ambient ColorScheme so an out-of-the-box host (no extension wired) still gets a usable, MD3-tonal chat. That also means a host can override just one field (say, the user bubble background to match their brand) and leave everything else at the sensible default.
Wiring example for a tenant:
MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink),
extensions: const [
ChatColors(
userBubbleBackground: Color(0xFFFCE4EC),
userBubbleForeground: Color(0xFF7A1D3F),
),
],
),
home: ChatWidget(/* ... */),
);
- Inheritance
-
- Object
- ThemeExtension<
ChatColors> - ChatColors
- Annotations
Constructors
Properties
- botBubbleBackground → Color?
-
Bot message bubble background. Default: ColorScheme.surface
(clean white in light themes; deep neutral in dark themes).
final
- botBubbleForeground → Color?
-
Foreground (text + icon) color for bot bubbles. Default:
ColorScheme.onSurface. Picks the readable contrast color for
whatever botBubbleBackground resolves to.
final
- botBubbleShadow → Color?
-
Drop-shadow color for bot bubbles. Default: a soft black at
~6% alpha — enough to lift the bubble off a same-color surface
without looking like a Material card.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- surfaceBackground → Color?
-
The chat surface — what sits behind the message list. Keep this
slightly off-white (or off-black in dark mode) so white/gray
bubbles read as raised cards rather than blending into the page.
Default: ColorScheme.surfaceContainerLow.
final
- type → Object
-
The extension's type.
no setterinherited
- userBubbleBackground → Color?
-
User message bubble background. Default:
ColorScheme.surfaceContainerHigh (a slightly darker tone than
the bot bubble so the two speakers read as distinct without
either looking like an error/accent surface). Override to a
brand-tinted color to give visitor messages a signature.
final
- userBubbleForeground → Color?
-
Foreground (text + icon) color for user bubbles. Default:
ColorScheme.onSurface over the lighter user bubble background.
final
Methods
-
copyWith(
{Color? surfaceBackground, Color? botBubbleBackground, Color? userBubbleBackground, Color? botBubbleForeground, Color? userBubbleForeground, Color? botBubbleShadow}) → ChatColors -
Creates a copy of this theme extension with the given fields
replaced by the non-null parameter values.
override
-
lerp(
covariant ThemeExtension< ChatColors> ? other, double t) → ChatColors -
Linearly interpolate with another ThemeExtension object.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolveBotBubble(
ColorScheme scheme) → Color -
resolveBotForeground(
ColorScheme scheme) → Color -
resolveBotShadow(
ColorScheme scheme) → Color -
resolveSurface(
ColorScheme scheme) → Color - Resolved chat-surface background. Pull-with-fallback so call sites stay terse.
-
resolveUserBubble(
ColorScheme scheme) → Color -
resolveUserForeground(
ColorScheme scheme) → Color -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of(
BuildContext context) → ChatColors - Look up the ChatColors from a BuildContext. Returns a const empty instance when the host hasn't wired one, so call sites never deal with null.