Chat: the transcript ends at the composer's top; the colour wash starts at the bar's top edge

This commit is contained in:
2026-11-03 12:27:53 +00:00
parent d34185b56c
commit 777c444529
7 changed files with 144 additions and 55 deletions
@@ -4,44 +4,73 @@ import '../../../core/api_gateway.dart';
import '../domain/chat_colors.dart';
import '../ui/sessions/chat_color_palette.dart';
/// The open chat's colour as a faint wash behind the top of the page: it
/// shows through the glass bar and fades out just below it, so even without
/// the list beside it the chat carries a gentle reminder of which one it is.
/// It sits under the transcript and takes no taps, so text contrast and
/// hit-testing are untouched. Nothing is drawn for a chat with no colour.
/// The open chat's colour as a faint wash over the top of the page: full
/// strength at the top edge of the bar, fading out a little below it, so even
/// without the list beside it the chat carries a gentle reminder of which one
/// it is. Nothing is drawn for a chat with no colour, and it takes no taps.
///
/// The bar's scrim is opaque at its top edge, so a wash only behind the
/// transcript would start below the bar. The wash is one gradient drawn in two
/// parts: [ChatColorWash.bar] over the scrim (the bar's backdrop) and
/// [ChatColorWash.belowBar] under the transcript, so text below the bar keeps
/// its contrast.
class ChatColorWash extends StatelessWidget {
const ChatColorWash({super.key, required this.session});
/// The part inside the bar, filling it as its backdrop.
const ChatColorWash.bar({super.key, required this.session}) : _bar = true;
/// The part below the bar, in a [Stack] under the transcript: it starts at
/// the bar's height, which arrives as the top padding.
const ChatColorWash.belowBar({super.key, required this.session})
: _bar = false;
final JsonMap? session;
final bool _bar;
/// How far past the bar's bottom edge the wash fades out.
static const double fadeBelowBar = 96;
@override
Widget build(BuildContext context) {
final color = chatColorShade(context, chatSessionColor(session));
if (color == null) return const SizedBox.shrink();
final strength = chatColorDarkSurface(context) ? 0.24 : 0.2;
// The bar's height arrives as top padding; the wash reaches a little
// past it so the fade reads under the bar, not as an edge at it.
final height = MediaQuery.paddingOf(context).top + 96;
return Positioned(
top: 0,
left: 0,
right: 0,
height: height,
child: IgnorePointer(
// The wash's alpha falls linearly from [strength] at the top to zero at
// the bar's height plus [fadeBelowBar]; each part draws its own stretch.
Widget wash(double barHeight, double from, double to) {
final total = barHeight + fadeBelowBar;
double alpha(double y) => strength * (1 - y / total);
return IgnorePointer(
child: DecoratedBox(
key: const Key('chat-color-wash'),
key: Key(_bar ? 'chat-color-wash' : 'chat-color-wash-below'),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
color.withValues(alpha: strength),
color.withValues(alpha: 0),
color.withValues(alpha: alpha(from)),
color.withValues(alpha: alpha(to)),
],
),
),
),
),
);
}
if (_bar) {
return LayoutBuilder(
builder: (context, constraints) {
final height = constraints.maxHeight;
return wash(height, 0, height);
},
);
}
final top = MediaQuery.paddingOf(context).top;
return Positioned(
top: top,
left: 0,
right: 0,
height: fadeBelowBar,
child: wash(top, top, top + fadeBelowBar),
);
}
}
@@ -19,6 +19,7 @@ class ChatThreadHeader extends StatelessWidget {
this.showBack = false,
this.onBack,
this.controls = const [],
this.backdrop,
});
final String title;
@@ -34,6 +35,9 @@ class ChatThreadHeader extends StatelessWidget {
final VoidCallback? onBack;
final List<Widget> controls;
/// Painted over the bar's scrim, under its pieces (the chat's colour).
final Widget? backdrop;
@override
Widget build(BuildContext context) {
final cupertino =
@@ -58,6 +62,7 @@ class ChatThreadHeader extends StatelessWidget {
titleKey: const Key('chat-info'),
actions: controls,
bottomPadding: 16,
backdrop: backdrop,
);
}
}
@@ -911,9 +911,10 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// Under the app shell the conversation takes over the app's bar (title,
// Back, model, information) instead of drawing a second bar below it.
final inShellBar = ShellBar.available(context);
// The transcript fills the page; the conversation's bar floats over its
// top and the frosted composer over its bottom, and history scrolls
// behind both.
// The conversation's bar floats over the transcript's top and history
// scrolls behind it; the transcript ends at the composer's top edge, so
// nothing renders behind the composer and the viewport shrinks as the
// composer grows.
// Every input of the composer comes from this widget's configuration,
// the composer, the images and the running state.
final composerBar = _chrome.widgetFor(
@@ -970,12 +971,13 @@ class _ChatThreadViewState extends State<ChatThreadView> {
),
];
_rowWidgets.prune();
return Stack(
final stack = Stack(
children: [
// Behind everything: the chat's colour under the bar.
ChatColorWash(session: widget.session),
// At rest the first item starts below the floating bar
// and the last one ends above the floating composer.
// Behind everything: the chat's colour below the bar
// (the bar draws its own part over its scrim).
ChatColorWash.belowBar(session: widget.session),
// At rest the first item starts below the floating bar;
// the viewport itself ends above the composer.
// Bottom-anchored at the split row, the newest rows are
// laid out first and older ones only when scrolled to.
ChatTranscriptScrollView(
@@ -990,7 +992,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
side,
media.top + 8,
side,
media.bottom + 8,
8,
),
children: [
if (initialLoad)
@@ -1093,7 +1095,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
if (showJump)
PositionedDirectional(
end: side + 16,
bottom: media.bottom + 16,
bottom: 16,
child: _ChatJumpToLatest(
key: const Key('chat-jump-to-latest'),
label: chatJumpToLatestLabel(newMessages),
@@ -1103,14 +1105,16 @@ class _ChatThreadViewState extends State<ChatThreadView> {
),
],
);
return AboveFloatingBar(child: stack);
},
),
),
),
),
);
// The bar, the composer and the jump control float over the transcript;
// the wheel over them scrolls it, as a page scrolls under fixed bars.
// The bar and the jump control float over the transcript and the
// composer sits below it; the wheel over them scrolls it, as a page
// scrolls under fixed bars.
final column = VerticalWheelForwarder(controller: _scroll, child: page);
if (!inShellBar) return column;
// The conversation draws its own floating bar; the page shows none.
@@ -1157,6 +1161,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
.lastWhere((part) => part.isNotEmpty, orElse: () => '');
return ChatThreadHeader(
key: const Key('chat-thread-header'),
// The chat's colour from the bar's top edge, over its scrim.
backdrop: ChatColorWash.bar(session: session),
title: widget.title.trim(),
folder: folder,
onInfo: _openInfo,
@@ -95,6 +95,26 @@ class BelowTopBar extends StatelessWidget {
);
}
/// Content that must not run behind the floating bar (a [FloatingBarOverlay]'s
/// bar, such as a composer): it ends at the bar's top edge, so the viewport
/// shrinks as the bar grows, and its subtree no longer sees the bar's height
/// as padding.
class AboveFloatingBar extends StatelessWidget {
const AboveFloatingBar({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) => Padding(
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
child: MediaQuery.removePadding(
context: context,
removeBottom: true,
child: child,
),
);
}
/// Empty space as tall as the floating bar's clearance
/// ([MediaQuery.paddingOf] bottom), ending a scrolling column so its last item
/// comes clear of the bar at rest.
+7
View File
@@ -54,6 +54,7 @@ class SegmentedBar extends StatefulWidget
this.pillColor,
this.foregroundColor,
this.bottomPadding = 8,
this.backdrop,
});
/// Which control family to draw. Required because the bar's reserved
@@ -116,6 +117,10 @@ class SegmentedBar extends StatefulWidget
/// Space between the pieces and the content below.
final double bottomPadding;
/// Painted over the scrim and under the pieces, filling the bar from its
/// top edge (a page's own tint, such as a chat's colour). It takes no taps.
final Widget? backdrop;
static const double _topPadding = 8;
/// The share of the bar the title keeps before the actions shrink.
@@ -461,6 +466,8 @@ class _SegmentedBarState extends State<SegmentedBar> {
),
),
),
if (widget.backdrop case final backdrop?)
Positioned.fill(child: IgnorePointer(child: backdrop)),
SafeArea(
bottom: false,
child: Padding(