30d2d8c4f4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
4.2 KiB
Dart
113 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../ui/theme/app_design_tokens.dart';
|
|
import '../sessions/chat_color_palette.dart';
|
|
import 'boxed/boxed_quote.dart';
|
|
import 'paper/paper_quote.dart';
|
|
import 'terminal/terminal_prompt_line.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 {
|
|
const ChatUserBubble({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
static const BorderRadius _radius = BorderRadius.all(Radius.circular(20));
|
|
static const EdgeInsets _padding = EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 10,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
switch (AppDesignTokens.of(context).transcript) {
|
|
case TranscriptStyle.prompt:
|
|
return TerminalPromptLine(child: child);
|
|
case TranscriptStyle.manuscript:
|
|
return PaperQuote(child: child);
|
|
case TranscriptStyle.boxed:
|
|
return BoxedQuote(child: child);
|
|
case TranscriptStyle.bubbles:
|
|
break;
|
|
}
|
|
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
|
// inside the bubble keeps its ink and background. A dense design draws
|
|
// a tighter bubble in its own corners.
|
|
final tokens = AppDesignTokens.of(context);
|
|
final density = tokens.density;
|
|
return Material(
|
|
color: chatBubbleFill(
|
|
context,
|
|
Theme.of(context).colorScheme.surfaceContainerHighest,
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
shape: RoundedRectangleBorder(borderRadius: tokens.corners(_radius)),
|
|
child: Padding(
|
|
padding: density.dense
|
|
? EdgeInsets.symmetric(
|
|
horizontal: density.inset(_padding.left),
|
|
vertical: density.space(_padding.top),
|
|
)
|
|
: _padding,
|
|
child: child,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The agent's answer drawn straight on the page. Material keeps a transparent
|
|
/// surface so disclosure ListTiles still paint their ink.
|
|
class ChatAgentSurface extends StatelessWidget {
|
|
const ChatAgentSurface({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
Material(type: MaterialType.transparency, child: child);
|
|
}
|
|
|
|
/// The transcript's reading text: the host's large body role, so answers read
|
|
/// at a comfortable size and still follow the operator's text scaling, in
|
|
/// the design's reading face and line height (Paper's serif).
|
|
TextStyle? chatMessageTextStyle(BuildContext context) => AppDesignTokens.of(
|
|
context,
|
|
).reading.apply(Theme.of(context).textTheme.bodyLarge);
|
|
|
|
/// The empty-line gap between two paragraphs of a reply: about one line of
|
|
/// body text at [fontSize] (else the ambient text size), scaled by the
|
|
/// operator's text scaling, so chunks read as separate paragraphs. A design
|
|
/// may set a tighter gap ([ReadingType.paragraphGap]).
|
|
double chatParagraphGap(BuildContext context, [double? fontSize]) {
|
|
final size = fontSize ?? DefaultTextStyle.of(context).style.fontSize ?? 14;
|
|
return MediaQuery.textScalerOf(context).scale(size) *
|
|
AppDesignTokens.of(context).reading.paragraphGap;
|
|
}
|