Merge branch 'worktree-agent-a1275d0f5d434eccb'
This commit is contained in:
@@ -350,15 +350,20 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
child: DetailPane(
|
||||
key: ValueKey('chat-pane-detail-${pane.id}'),
|
||||
destination: AppDestination.chat,
|
||||
implyBack: false,
|
||||
builder: (context) => _thread(
|
||||
pane.sessionId,
|
||||
_back,
|
||||
pane: pane,
|
||||
paneContext: context,
|
||||
// Every pane's bar carries its own chat's colour; beside the
|
||||
// active pane the others fade theirs.
|
||||
child: ChatPaneActivity(
|
||||
inactive: _workspace.paneCount > 1 && !active,
|
||||
child: DetailPane(
|
||||
key: ValueKey('chat-pane-detail-${pane.id}'),
|
||||
destination: AppDestination.chat,
|
||||
implyBack: false,
|
||||
builder: (context) => _thread(
|
||||
pane.sessionId,
|
||||
_back,
|
||||
pane: pane,
|
||||
paneContext: context,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'chat_bar_tint.dart';
|
||||
|
||||
/// The conversation bar's model and mode controls read as the bar's other
|
||||
/// actions do: neutral, not tinted like a primary call to action.
|
||||
/// actions do: neutral, not tinted like a primary call to action. In a
|
||||
/// coloured chat's bar they take its foreground ([ChatBarTintScope]) instead.
|
||||
///
|
||||
/// Material: a [TextButton] style in the role the bar's icon buttons use
|
||||
/// (`onSurfaceVariant`).
|
||||
ButtonStyle chatBarTextButtonStyle(BuildContext context) =>
|
||||
TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
foregroundColor:
|
||||
ChatBarTintScope.foregroundOf(context) ??
|
||||
Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
);
|
||||
|
||||
/// Cupertino: [content] (a [CupertinoButton]'s child) in the label colour
|
||||
/// instead of the button's tint.
|
||||
Widget chatBarCupertinoContent(BuildContext context, Widget content) {
|
||||
final color = CupertinoColors.label.resolveFrom(context);
|
||||
final color =
|
||||
ChatBarTintScope.foregroundOf(context) ??
|
||||
CupertinoColors.label.resolveFrom(context);
|
||||
return IconTheme.merge(
|
||||
data: IconThemeData(color: color),
|
||||
child: DefaultTextStyle.merge(
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/glass_pill.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import '../ui/sessions/chat_color_palette.dart';
|
||||
|
||||
/// How strongly the chat's shade colours the bar's glass pieces over the
|
||||
/// host's raised surface, on a light and on a dark page. The dark value stays
|
||||
/// at the low end so a warm hue (amber) keeps its own colour over the dark
|
||||
/// grey instead of turning olive.
|
||||
const double chatBarTintLight = 0.16;
|
||||
const double chatBarTintDark = 0.16;
|
||||
|
||||
/// The share of the tint an inactive split pane's bar keeps.
|
||||
const double chatBarInactiveFade = 0.5;
|
||||
|
||||
/// A Material tonal scheme seeded from [shade] in the page's brightness: its
|
||||
/// `onPrimaryContainer` labels the tinted bar and its `primary` (tone 40 on
|
||||
/// light, 80 on dark) draws the composer's focus ring.
|
||||
ColorScheme chatSeededScheme(Color shade, {required bool dark}) =>
|
||||
ColorScheme.fromSeed(
|
||||
seedColor: shade,
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
);
|
||||
|
||||
/// A coloured chat's bar: the glass pieces' [fill] (translucent as every
|
||||
/// glass piece is, unless solid) and the [foreground] its labels, icons and
|
||||
/// controls draw in.
|
||||
@immutable
|
||||
class ChatBarTint {
|
||||
const ChatBarTint({required this.fill, required this.foreground});
|
||||
|
||||
/// The bar's colours for [shade] over the host's [raised] surface. An
|
||||
/// [inactive] split pane keeps [chatBarInactiveFade] of the tint; [solid]
|
||||
/// (the system's high-contrast setting) leaves the fill opaque, as the
|
||||
/// glass does then.
|
||||
factory ChatBarTint.from({
|
||||
required Color shade,
|
||||
required Color raised,
|
||||
required bool dark,
|
||||
bool inactive = false,
|
||||
bool solid = false,
|
||||
}) {
|
||||
final strength =
|
||||
(dark ? chatBarTintDark : chatBarTintLight) *
|
||||
(inactive ? chatBarInactiveFade : 1);
|
||||
final opaque = Color.alphaBlend(shade.withValues(alpha: strength), raised);
|
||||
return ChatBarTint(
|
||||
fill: solid ? opaque : opaque.withValues(alpha: GlassPill.fillOpacity),
|
||||
foreground: chatSeededScheme(shade, dark: dark).onPrimaryContainer,
|
||||
);
|
||||
}
|
||||
|
||||
final Color fill;
|
||||
final Color foreground;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is ChatBarTint &&
|
||||
other.fill == fill &&
|
||||
other.foreground == foreground;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(fill, foreground);
|
||||
}
|
||||
|
||||
/// The bar tint for the chat colour [name] on this host, or null for a chat
|
||||
/// with no colour (its bar stays neutral). Reads [ChatPaneActivity].
|
||||
ChatBarTint? chatBarTintOf(BuildContext context, String? name) {
|
||||
final shade = chatColorShade(context, name);
|
||||
if (shade == null) return null;
|
||||
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
return ChatBarTint.from(
|
||||
shade: shade,
|
||||
raised: cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
dark: chatColorDarkSurface(context),
|
||||
inactive: ChatPaneActivity.inactiveOf(context),
|
||||
solid: MediaQuery.maybeHighContrastOf(context) ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
/// 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.
|
||||
Color chatFocusRingColor(BuildContext context, String? name) {
|
||||
final shade = chatColorShade(context, name);
|
||||
if (shade != null) {
|
||||
return chatSeededScheme(shade, dark: chatColorDarkSurface(context)).primary;
|
||||
}
|
||||
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
}
|
||||
|
||||
/// Marks a split pane that is not the active one, so its bar fades its tint.
|
||||
class ChatPaneActivity extends InheritedWidget {
|
||||
const ChatPaneActivity({
|
||||
super.key,
|
||||
required this.inactive,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
final bool inactive;
|
||||
|
||||
static bool inactiveOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<ChatPaneActivity>()?.inactive ??
|
||||
false;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ChatPaneActivity oldWidget) =>
|
||||
inactive != oldWidget.inactive;
|
||||
}
|
||||
|
||||
/// Gives the bar's controls the tint's foreground: Material icon buttons
|
||||
/// through the ambient icon colour, Cupertino buttons (Back, Files, More)
|
||||
/// through the theme's primary colour, their native tint, and the chat's own
|
||||
/// bar controls through [foregroundOf].
|
||||
class ChatBarTintScope extends InheritedWidget {
|
||||
ChatBarTintScope({
|
||||
super.key,
|
||||
required this.tint,
|
||||
required bool cupertino,
|
||||
required Widget child,
|
||||
}) : super(
|
||||
child: Builder(
|
||||
builder: (context) => cupertino
|
||||
? CupertinoTheme(
|
||||
data: CupertinoTheme.of(
|
||||
context,
|
||||
).copyWith(primaryColor: tint.foreground),
|
||||
child: child,
|
||||
)
|
||||
: IconTheme.merge(
|
||||
data: IconThemeData(color: tint.foreground),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final ChatBarTint tint;
|
||||
|
||||
/// The tinted bar's foreground around [context], or null in a neutral bar.
|
||||
static Color? foregroundOf(BuildContext context) => context
|
||||
.dependOnInheritedWidgetOfExactType<ChatBarTintScope>()
|
||||
?.tint
|
||||
.foreground;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(ChatBarTintScope oldWidget) =>
|
||||
tint != oldWidget.tint;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overlay.dart';
|
||||
import '../domain/chat_colors.dart';
|
||||
import '../ui/sessions/chat_color_palette.dart';
|
||||
|
||||
/// 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 {
|
||||
/// 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 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: Key(_bar ? 'chat-color-wash' : 'chat-color-wash-below'),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
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;
|
||||
final barHeight = top + SegmentedBarOverlay.reservedHeightOf(context);
|
||||
return Positioned(
|
||||
top: top,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: fadeBelowBar,
|
||||
child: wash(barHeight, barHeight, barHeight + fadeBelowBar),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@ import '../../../ui/adaptive/pop_entrance.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import 'composer_focus_request.dart';
|
||||
import 'composer_focus_restore.dart';
|
||||
import 'chat_bar_tint.dart';
|
||||
import 'composer_focus_ring.dart';
|
||||
import '../ui/sessions/chat_color_palette.dart';
|
||||
import '../shell/chat_shell_command.dart';
|
||||
import '../shell/chat_shell_mode_indicator.dart';
|
||||
|
||||
@@ -964,11 +964,11 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// The field and its controls in one frosted-glass surface floating over
|
||||
/// the transcript, so the composer reads as a single input rather than a
|
||||
/// row of separate controls, and the conversation shows through it. While
|
||||
/// the field has focus the pill's edge takes the chat's accent.
|
||||
/// the field has focus a ring in the chat's colour runs along its edge.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) =>
|
||||
ComposerFocusRing(
|
||||
focus: _focus,
|
||||
accent: _accent(context, cupertino),
|
||||
accent: chatFocusRingColor(context, widget.chatColor),
|
||||
shape: _pillShape,
|
||||
child: GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
@@ -983,13 +983,6 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
),
|
||||
);
|
||||
|
||||
/// The chat's accent: its own colour's shade for this host and brightness,
|
||||
/// else the host's primary colour.
|
||||
Color _accent(BuildContext context, bool cupertino) =>
|
||||
chatColorShade(context, widget.chatColor) ??
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary);
|
||||
|
||||
/// 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.
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../ui/adaptive/segmented_bar.dart';
|
||||
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_bar_tint.dart';
|
||||
|
||||
/// The open conversation's bar: the app's [SegmentedBar] above the
|
||||
/// transcript.
|
||||
@@ -15,6 +16,11 @@ import '../ui/sessions/chat_adaptive.dart';
|
||||
/// then the Files action and a native More menu in a separate island.
|
||||
/// Narrow panes keep the model/mode selectors as compact icons in the same row;
|
||||
/// their semantic labels and native pickers continue to expose the values.
|
||||
///
|
||||
/// A chat with a [chatColor] carries it in the bar: each glass piece is
|
||||
/// filled with its shade over the raised surface and its labels and icons
|
||||
/// take the colour's foreground ([chatBarTintOf]), faded in an inactive split
|
||||
/// pane. A chat with none keeps the neutral bar.
|
||||
class ChatThreadHeader extends StatelessWidget {
|
||||
const ChatThreadHeader({
|
||||
super.key,
|
||||
@@ -26,7 +32,7 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
this.controls = const [],
|
||||
this.actions = const [],
|
||||
this.moreActions = const [],
|
||||
this.backdrop,
|
||||
this.chatColor,
|
||||
this.identity,
|
||||
this.identityHeroTag,
|
||||
});
|
||||
@@ -46,8 +52,8 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
final List<Widget> actions;
|
||||
final List<Widget> moreActions;
|
||||
|
||||
/// Painted over the bar's scrim, under its pieces (the chat's colour).
|
||||
final Widget? backdrop;
|
||||
/// The chat's colour name, or null for none.
|
||||
final String? chatColor;
|
||||
|
||||
/// The chat identity carried from the mobile session row into this header.
|
||||
final Widget? identity;
|
||||
@@ -57,6 +63,7 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final tint = chatBarTintOf(context, chatColor);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final textScale = MediaQuery.textScalerOf(context).scale(14) / 14;
|
||||
@@ -67,8 +74,10 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
(MediaQuery.maybeDisableAnimationsOf(context) ?? false)
|
||||
? identity
|
||||
: Hero(tag: identityHeroTag!, child: identity!);
|
||||
final bar = SegmentedBar(
|
||||
final Widget bar = SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
pillColor: tint?.fill,
|
||||
foregroundColor: tint?.foreground,
|
||||
automaticallyImplyLeading: false,
|
||||
// The platform's own Back, so it reads and behaves as every other
|
||||
// page's Back; its key stays for finders.
|
||||
@@ -118,13 +127,19 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
bottomPadding: compact ? 8 : 16,
|
||||
backdrop: backdrop,
|
||||
);
|
||||
return ColoredBox(
|
||||
color: cupertino
|
||||
? CupertinoTheme.of(context).scaffoldBackgroundColor
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
child: bar,
|
||||
child: tint == null
|
||||
? bar
|
||||
: ChatBarTintScope(
|
||||
key: const Key('chat-bar-tint'),
|
||||
tint: tint,
|
||||
cupertino: cupertino,
|
||||
child: bar,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -37,7 +37,6 @@ import 'chat_account_usage_section.dart';
|
||||
import 'chat_export_controller.dart';
|
||||
import 'chat_session_section.dart';
|
||||
import 'chat_background_tasks.dart';
|
||||
import 'chat_color_wash.dart';
|
||||
import 'chat_command_actions.dart';
|
||||
import 'chat_composer_bar.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
@@ -1180,9 +1179,6 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
_rowWidgets.prune();
|
||||
final stack = Stack(
|
||||
children: [
|
||||
// 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
|
||||
@@ -1389,8 +1385,7 @@ 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),
|
||||
chatColor: chatSessionColor(session),
|
||||
title: widget.title.trim(),
|
||||
folder: folder,
|
||||
identity:
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// The composer's focus indication: a thin ring in the chat's accent colour
|
||||
/// along the pill's edge and a soft glow of the same colour outside it, so
|
||||
/// a focused field shows as such without relying on its caret alone. Both
|
||||
/// fade in and out with focus; at rest unfocused nothing visible is drawn.
|
||||
/// The composer's focus indication: a solid ring in the chat's accent colour
|
||||
/// along the pill's edge, so a focused field shows as such without relying
|
||||
/// on its caret alone. It fades in and out with focus; at rest unfocused
|
||||
/// nothing visible is drawn.
|
||||
///
|
||||
/// The accent is the chat's own colour (its highlight in the list) when it
|
||||
/// has one, else the host's primary colour, never the pill's background: the
|
||||
/// ring is translucent so the same tint stays subtle on a light and a dark
|
||||
/// pill.
|
||||
/// The accent is the focus colour of the chat's own colour (the `primary`
|
||||
/// of a scheme seeded from it, `chatFocusRingColor`) when it has one, else
|
||||
/// the host's primary colour. It is drawn at full opacity, so it keeps 3:1
|
||||
/// against the page for every chat colour in light and dark.
|
||||
class ComposerFocusRing extends StatelessWidget {
|
||||
const ComposerFocusRing({
|
||||
super.key,
|
||||
@@ -21,7 +21,7 @@ class ComposerFocusRing extends StatelessWidget {
|
||||
/// The field's focus node; the ring follows its [FocusNode.hasFocus].
|
||||
final FocusNode focus;
|
||||
|
||||
/// The chat's accent, at full opacity; the ring and glow fade it.
|
||||
/// The ring's colour while focused.
|
||||
final Color accent;
|
||||
|
||||
/// The pill's shape, so the ring hugs its edge.
|
||||
@@ -32,17 +32,7 @@ class ComposerFocusRing extends StatelessWidget {
|
||||
static const Duration duration = Duration(milliseconds: 160);
|
||||
|
||||
/// The ring's stroke, drawn just inside the pill's edge over its hairline.
|
||||
static const double ringWidth = 1.5;
|
||||
|
||||
/// The accent's opacity in the ring while focused.
|
||||
static const double ringOpacity = 0.6;
|
||||
|
||||
/// The accent's opacity in the glow while focused.
|
||||
static const double glowOpacity = 0.18;
|
||||
|
||||
/// The glow's blur radius; it spreads [glowSpread] past the pill first.
|
||||
static const double glowBlur = 12;
|
||||
static const double glowSpread = 1;
|
||||
static const double ringWidth = 2;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
@@ -50,27 +40,17 @@ class ComposerFocusRing extends StatelessWidget {
|
||||
child: child,
|
||||
builder: (context, child) {
|
||||
final focused = focus.hasFocus;
|
||||
// Both decorations keep the same shape, shadow and stroke while only
|
||||
// their colours change, so the container lerps them into one fade.
|
||||
// The decoration keeps the same shape and stroke while only its colour
|
||||
// changes, so the container lerps it into one fade.
|
||||
return AnimatedContainer(
|
||||
key: const Key('chat-composer-focus-ring'),
|
||||
duration: duration,
|
||||
curve: Curves.easeOutCubic,
|
||||
decoration: ShapeDecoration(
|
||||
shape: shape,
|
||||
shadows: [
|
||||
BoxShadow(
|
||||
color: accent.withValues(alpha: focused ? glowOpacity : 0),
|
||||
blurRadius: glowBlur,
|
||||
spreadRadius: glowSpread,
|
||||
),
|
||||
],
|
||||
),
|
||||
// Over the child: the pill's fill would otherwise cover the ring.
|
||||
foregroundDecoration: ShapeDecoration(
|
||||
shape: shape.copyWith(
|
||||
side: BorderSide(
|
||||
color: accent.withValues(alpha: focused ? ringOpacity : 0),
|
||||
color: accent.withValues(alpha: focused ? 1 : 0),
|
||||
width: ringWidth,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -22,6 +22,7 @@ import '../../core/servers/server_scope.dart';
|
||||
import 'workspace/chat_workspace_binding.dart';
|
||||
import 'workspace/chat_workspace_snapshot.dart';
|
||||
import 'workspace/chat_workspace_store.dart';
|
||||
import 'conversation/chat_bar_tint.dart';
|
||||
import 'conversation/chat_efforts.dart';
|
||||
import 'conversation/chat_models.dart';
|
||||
import 'conversation/chat_pane_picker.dart';
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
# Chat colour in the thread bar (UI review option B)
|
||||
|
||||
## Spec as implemented
|
||||
|
||||
- Thread bar glass pieces (Back, title pill, model/mode/thinking island,
|
||||
Files+More island) take the chat colour through `SegmentedBar.pillColor`:
|
||||
fill = `chatColorShade` blended over the host raised surface (Material
|
||||
`surfaceContainerHigh`, Cupertino `systemGrey5`) at **0.16 in light and
|
||||
dark**, then the glass `fillOpacity` 0.82. It stays opaque under the
|
||||
high-contrast setting, as the neutral glass does. Dark uses 0.16 (not
|
||||
0.18) so amber keeps reading as dark gold and does not turn olive.
|
||||
- Foreground = `ColorScheme.fromSeed(seedColor: shade, brightness).onPrimaryContainer`
|
||||
on both hosts. Material passes it as `SegmentedBar.foregroundColor` (title and
|
||||
subtitle) and as the ambient `IconTheme` (Back, Files and More icon buttons).
|
||||
`chatBarTextButtonStyle` (model/mode/thinking) reads `ChatBarTintScope`.
|
||||
Cupertino passes it as the bar's `CupertinoTheme.primaryColor`, so Back,
|
||||
Files and More take it as their native tint, and through
|
||||
`chatBarCupertinoContent` for the selectors. The raw Cupertino system colour
|
||||
is not used for text because `systemYellow` on light grey is about 1.5:1.
|
||||
- Split panes: each pane's bar carries its own colour. A pane that is not the
|
||||
active one (`ChatPaneActivity`, set by the workspace when there is more than
|
||||
one pane) keeps `chatBarInactiveFade` = 0.5 of the tint strength. The active
|
||||
pane keeps its border (unchanged) and the composer focus ring.
|
||||
- Chats with no colour keep the neutral bar: no scope, `pillColor` is null.
|
||||
- `ChatColorWash` (bar backdrop and below-bar gradient) is removed.
|
||||
- Composer: no fill tint. The focus ring is the seeded scheme's `primary`
|
||||
(tone 40 light / 80 dark), or the host primary for a chat with no colour.
|
||||
It is drawn at full opacity, 2 px, with no glow.
|
||||
- Sidebar row tint, edge marker and avatar are unchanged.
|
||||
|
||||
Code: `lib/features/chat/conversation/chat_bar_tint.dart` (tint maths,
|
||||
`ChatPaneActivity`, `ChatBarTintScope`), `chat_thread_header.dart`,
|
||||
`chat_bar_control_style.dart`, `composer_focus_ring.dart`,
|
||||
`chat_composer_bar.dart`, `chat_thread_view.dart`, `chat_screen_workspace.dart`.
|
||||
|
||||
## Contrast (WCAG, `test/features/chat/conversation/chat_bar_tint_contrast_test.dart`)
|
||||
|
||||
The test reads shades through `chatColorShade` under the app's themes and
|
||||
asserts labels ≥ 4.5:1 (active, inactive and solid fill, with the glass over
|
||||
the page) and the ring ≥ 3:1 against the page and the composer glass.
|
||||
Minimums across all 8 colours × 2 hosts × 2 brightnesses:
|
||||
bar label 6.42, inactive label 7.10, solid label 5.95, ring vs page 6.10,
|
||||
ring vs composer 5.35. Set `CHAT_BAR_CONTRAST_OUT=<file>` to write the table.
|
||||
|
||||
| host | theme | colour | bar label | inactive label | solid label | ring vs page | ring vs composer |
|
||||
|---|---|---|---|---|---|---|---|
|
||||
| material | light | red | 6.64 | 7.23 | 6.21 | 6.13 | 5.42 |
|
||||
| material | light | orange | 6.92 | 7.37 | 6.54 | 6.16 | 5.44 |
|
||||
| material | light | amber | 7.15 | 7.47 | 6.81 | 6.15 | 5.43 |
|
||||
| material | light | green | 6.81 | 7.31 | 6.41 | 6.10 | 5.39 |
|
||||
| material | light | teal | 6.74 | 7.28 | 6.32 | 6.10 | 5.39 |
|
||||
| material | light | blue | 6.68 | 7.23 | 6.26 | 6.10 | 5.39 |
|
||||
| material | light | purple | 6.42 | 7.11 | 5.95 | 6.13 | 5.42 |
|
||||
| material | light | pink | 6.44 | 7.10 | 5.98 | 6.14 | 5.43 |
|
||||
| material | dark | red | 9.95 | 10.96 | 9.02 | 10.81 | 9.06 |
|
||||
| material | dark | orange | 9.01 | 10.45 | 7.96 | 10.78 | 9.04 |
|
||||
| material | dark | amber | 8.64 | 10.25 | 7.56 | 10.82 | 9.07 |
|
||||
| material | dark | green | 9.20 | 10.53 | 8.18 | 10.83 | 9.08 |
|
||||
| material | dark | teal | 9.60 | 10.78 | 8.62 | 10.80 | 9.05 |
|
||||
| material | dark | blue | 9.39 | 10.65 | 8.39 | 10.84 | 9.09 |
|
||||
| material | dark | purple | 10.17 | 11.07 | 9.28 | 10.81 | 9.07 |
|
||||
| material | dark | pink | 10.06 | 11.02 | 9.14 | 10.82 | 9.07 |
|
||||
| cupertino | light | red | 6.61 | 7.15 | 6.10 | 6.47 | 5.38 |
|
||||
| cupertino | light | orange | 7.18 | 7.48 | 6.75 | 6.49 | 5.39 |
|
||||
| cupertino | light | amber | 7.52 | 7.65 | 7.16 | 6.43 | 5.35 |
|
||||
| cupertino | light | green | 7.19 | 7.49 | 6.75 | 6.45 | 5.36 |
|
||||
| cupertino | light | teal | 7.29 | 7.51 | 6.90 | 6.49 | 5.40 |
|
||||
| cupertino | light | blue | 6.68 | 7.20 | 6.17 | 6.45 | 5.36 |
|
||||
| cupertino | light | purple | 6.70 | 7.20 | 6.20 | 6.48 | 5.38 |
|
||||
| cupertino | light | pink | 6.59 | 7.16 | 6.07 | 6.45 | 5.36 |
|
||||
| cupertino | dark | red | 10.02 | 10.76 | 9.09 | 10.83 | 8.70 |
|
||||
| cupertino | dark | orange | 9.01 | 10.23 | 7.95 | 10.81 | 8.68 |
|
||||
| cupertino | dark | amber | 8.29 | 9.80 | 7.18 | 10.79 | 8.67 |
|
||||
| cupertino | dark | green | 8.97 | 10.18 | 7.92 | 10.83 | 8.70 |
|
||||
| cupertino | dark | teal | 8.64 | 10.02 | 7.56 | 10.84 | 8.71 |
|
||||
| cupertino | dark | blue | 9.96 | 10.73 | 9.02 | 10.80 | 8.67 |
|
||||
| cupertino | dark | purple | 9.85 | 10.66 | 8.90 | 10.82 | 8.69 |
|
||||
| cupertino | dark | pink | 10.17 | 10.86 | 9.25 | 10.78 | 8.66 |
|
||||
|
||||
## Verification
|
||||
|
||||
- `tool/analyze.sh`: `analyze: clean; exit 0`.
|
||||
- `tool/memwatch/full.sh 'test/features/chat'`:
|
||||
`PASS: 1176 passed, 0 failed, 0 skipped; peak 2186 MB; 136s; exit 0`.
|
||||
- Widget tests: `chat_bar_tint_test.dart` covers the tinted and neutral bar, the
|
||||
Material and Cupertino foreground (icons, Back, selectors, title), and the
|
||||
inactive fade. `chat_workspace_insets_color_test.dart` checks per-pane
|
||||
colours, the fade following the active pane, and the neutral pane.
|
||||
`chat_list_shortcuts_test.dart` checks that no wash is drawn and the bar is
|
||||
tinted. `chat_composer_focus_ring_test.dart` checks the opaque 2 px seeded or
|
||||
host primary ring with no glow.
|
||||
- Real Chrome (`tool/capture`, fixture `tool/search_selection_probe_entry.dart`,
|
||||
`?chats=7&rich=1&colors=1&header=1`): 560x1000 phone purple, amber and plain
|
||||
chats, unfocused and focused. Also 1400x900 split into four panes through
|
||||
"Open to the right" and "Open below", with the focused composer. Captured in
|
||||
Material light, Material dark and Cupertino light under `/tmp/cbar/shots/`,
|
||||
with contact sheets at `/tmp/cbar/sheet-*.png`. All were inspected. The
|
||||
inactive panes show the lighter tint, the plain chat's bar is neutral, the
|
||||
ring is solid and in the chat's hue, and dark amber reads as dark gold.
|
||||
@@ -3,9 +3,11 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
@@ -237,8 +239,8 @@ void main() {
|
||||
final host =
|
||||
'${platform == TargetPlatform.iOS ? 'Cupertino' : 'Material'} '
|
||||
'${brightness.name}';
|
||||
testWidgets('$host: a coloured chat washes its top; the info sheet '
|
||||
'changes the colour', (tester) async {
|
||||
testWidgets('$host: a coloured chat tints its bar, with no wash; the '
|
||||
'info sheet changes the colour', (tester) async {
|
||||
final gateway = await _pumpShell(
|
||||
tester,
|
||||
const Size(1280, 800),
|
||||
@@ -247,37 +249,26 @@ void main() {
|
||||
);
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit1);
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
final washRect = tester.getRect(
|
||||
find.byKey(const Key('chat-color-wash')),
|
||||
);
|
||||
final pane = tester.getRect(
|
||||
find.byKey(const ValueKey('chat-detail-pane')),
|
||||
);
|
||||
// The wash starts at the very top of the pane, the bar's top edge,
|
||||
// over the bar's scrim, and carries on below the bar to fade out.
|
||||
expect(washRect.top, pane.top);
|
||||
final bar = tester.getRect(find.byKey(const Key('chat-thread-header')));
|
||||
expect(bar.top, pane.top);
|
||||
expect(washRect.bottom, bar.bottom);
|
||||
final below = find.byKey(const Key('chat-color-wash-below'));
|
||||
expect(tester.getRect(below).top, bar.bottom);
|
||||
expect(tester.getRect(below).bottom, lessThan(pane.height / 4));
|
||||
LinearGradient gradientOf(Finder finder) =>
|
||||
(tester.widget<DecoratedBox>(finder).decoration as BoxDecoration)
|
||||
.gradient!
|
||||
as LinearGradient;
|
||||
final top = gradientOf(find.byKey(const Key('chat-color-wash')));
|
||||
final rest = gradientOf(below);
|
||||
expect(top.colors.first.a, greaterThan(0.15));
|
||||
expect(top.colors.first.a, lessThanOrEqualTo(0.25));
|
||||
// One continuous fade across the two parts.
|
||||
expect(rest.colors.first.a, closeTo(top.colors.last.a, 1e-6));
|
||||
expect(rest.colors.last.a, 0);
|
||||
|
||||
// A plain chat has none.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
// The colour lives in the bar's pieces; the page has no wash.
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-color-wash-below')), findsNothing);
|
||||
final tint = tester.widget<ChatBarTintScope>(
|
||||
find.byKey(const Key('chat-bar-tint')),
|
||||
);
|
||||
final pill = tester.widget<GlassPill>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byKey(const Key('chat-info')),
|
||||
matching: find.byType(GlassPill),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(pill.fill, tint.tint.fill);
|
||||
|
||||
// A plain chat keeps the neutral bar.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -289,7 +280,7 @@ void main() {
|
||||
});
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
@@ -174,6 +175,55 @@ void main() {
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('each pane bar carries its own colour; inactive ones fade', (
|
||||
tester,
|
||||
) async {
|
||||
await _mount(tester, const Size(1800, 1000));
|
||||
final controller = tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||
.controller;
|
||||
ChatBarTint tintOf(String id) => tester
|
||||
.widget<ChatBarTintScope>(
|
||||
find.descendant(
|
||||
of: _thread(id),
|
||||
matching: find.byKey(const Key('chat-bar-tint')),
|
||||
),
|
||||
)
|
||||
.tint;
|
||||
ChatBarTint expected(String id, String color, {required bool inactive}) {
|
||||
final context = tester.element(_thread(id));
|
||||
return ChatBarTint.from(
|
||||
shade: chatColorShade(context, color)!,
|
||||
raised: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
dark: false,
|
||||
inactive: inactive,
|
||||
);
|
||||
}
|
||||
|
||||
// One pane alone is active.
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: false));
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: true));
|
||||
expect(tintOf('b'), expected('b', 'teal', inactive: false));
|
||||
controller.activate(
|
||||
controller.panes.firstWhere((p) => p.sessionId == 'a').id,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: false));
|
||||
expect(tintOf('b'), expected('b', 'teal', inactive: true));
|
||||
// A chat with no colour keeps the neutral bar in its pane.
|
||||
controller.splitActive('c', ChatSplitAxis.vertical);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _thread('c'),
|
||||
matching: find.byKey(const Key('chat-bar-tint')),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('wide panes leave the shared divider to the workspace', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_colors.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
double _luminance(Color c) {
|
||||
double channel(double v) =>
|
||||
v <= 0.03928 ? v / 12.92 : math.pow((v + 0.055) / 1.055, 2.4).toDouble();
|
||||
return 0.2126 * channel(c.r) + 0.7152 * channel(c.g) + 0.0722 * channel(c.b);
|
||||
}
|
||||
|
||||
/// WCAG contrast of [a] against [b], both opaque.
|
||||
double _ratio(Color a, Color b) {
|
||||
final x = _luminance(a), y = _luminance(b);
|
||||
return (math.max(x, y) + 0.05) / (math.min(x, y) + 0.05);
|
||||
}
|
||||
|
||||
/// The colours one host draws a chat's bar and composer with.
|
||||
typedef _Host = ({Color page, Color raised, Color shade});
|
||||
|
||||
/// Every palette colour's shade on one host and brightness, read through
|
||||
/// the app's own [chatColorShade] under the app's theme.
|
||||
Future<Map<String, _Host>> _hostColours(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
required bool dark,
|
||||
}) async {
|
||||
final result = <String, _Host>{};
|
||||
final brightness = dark ? Brightness.dark : Brightness.light;
|
||||
Widget probe() => Builder(
|
||||
builder: (context) {
|
||||
for (final name in chatColorNames) {
|
||||
result[name] = (
|
||||
page: cupertino
|
||||
? AppColors.background.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
raised: cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
shade: chatColorShade(context, name)!,
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: appCupertinoTheme.copyWith(brightness: brightness),
|
||||
home: probe(),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: dark ? appDarkTheme() : appLightTheme(),
|
||||
home: probe(),
|
||||
),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final rows = <String>['host\ttheme\tcolour\tmeasure\tratio\tminimum'];
|
||||
|
||||
tearDownAll(() {
|
||||
final out = Platform.environment['CHAT_BAR_CONTRAST_OUT'];
|
||||
if (out != null) File(out).writeAsStringSync('${rows.join('\n')}\n');
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final dark in [false, true]) {
|
||||
final host = cupertino ? 'cupertino' : 'material';
|
||||
final theme = dark ? 'dark' : 'light';
|
||||
testWidgets('$host $theme: every chat colour meets AA in the bar and '
|
||||
'the focus ring', (tester) async {
|
||||
final colours = await _hostColours(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
dark: dark,
|
||||
);
|
||||
expect(colours.keys, chatColorNames);
|
||||
void check(String name, String what, double ratio, double minimum) {
|
||||
rows.add(
|
||||
'$host\t$theme\t$name\t$what\t'
|
||||
'${ratio.toStringAsFixed(2)}\t$minimum',
|
||||
);
|
||||
expect(
|
||||
ratio,
|
||||
greaterThanOrEqualTo(minimum),
|
||||
reason: '$host $theme $name: $what',
|
||||
);
|
||||
}
|
||||
|
||||
for (final MapEntry(key: name, value: c) in colours.entries) {
|
||||
for (final inactive in [false, true]) {
|
||||
final tint = ChatBarTint.from(
|
||||
shade: c.shade,
|
||||
raised: c.raised,
|
||||
dark: dark,
|
||||
inactive: inactive,
|
||||
);
|
||||
// The glass lies over the bar's scrim, the page's colour.
|
||||
final pill = Color.alphaBlend(tint.fill, c.page);
|
||||
check(
|
||||
name,
|
||||
inactive ? 'inactive bar label' : 'bar label',
|
||||
_ratio(tint.foreground, pill),
|
||||
4.5,
|
||||
);
|
||||
// Solid under the system's high-contrast setting.
|
||||
final solid = ChatBarTint.from(
|
||||
shade: c.shade,
|
||||
raised: c.raised,
|
||||
dark: dark,
|
||||
inactive: inactive,
|
||||
solid: true,
|
||||
);
|
||||
check(
|
||||
name,
|
||||
inactive ? 'inactive solid bar label' : 'solid bar label',
|
||||
_ratio(solid.foreground, solid.fill),
|
||||
4.5,
|
||||
);
|
||||
}
|
||||
final ring = chatSeededScheme(c.shade, dark: dark).primary;
|
||||
check(name, 'focus ring vs page', _ratio(ring, c.page), 3);
|
||||
final composer = Color.alphaBlend(
|
||||
c.raised.withValues(alpha: GlassPill.fillOpacity),
|
||||
c.page,
|
||||
);
|
||||
check(name, 'focus ring vs composer', _ratio(ring, composer), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_control_style.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
/// A header in the app's theme, with one model-style control, Files, and an
|
||||
/// optional split-pane activity around it.
|
||||
Widget _header({
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
bool? inactive,
|
||||
}) {
|
||||
Widget header = ChatThreadHeader(
|
||||
title: 'Colour chat',
|
||||
folder: 'demo',
|
||||
onInfo: () {},
|
||||
showBack: true,
|
||||
onBack: () {},
|
||||
chatColor: color,
|
||||
controls: [
|
||||
Builder(
|
||||
builder: (context) => cupertino
|
||||
? CupertinoButton(
|
||||
onPressed: () {},
|
||||
child: chatBarCupertinoContent(context, const Text('Model')),
|
||||
)
|
||||
: TextButton(
|
||||
style: chatBarTextButtonStyle(context),
|
||||
onPressed: () {},
|
||||
child: const Text('Model'),
|
||||
),
|
||||
),
|
||||
],
|
||||
actions: [
|
||||
ChatBarAction(
|
||||
label: 'Files',
|
||||
onPressed: () {},
|
||||
materialIcon: Icons.folder_outlined,
|
||||
cupertinoIcon: CupertinoIcons.folder,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (inactive != null) {
|
||||
header = ChatPaneActivity(inactive: inactive, child: header);
|
||||
}
|
||||
final body = Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: SizedBox(width: 900, height: 120, child: header),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
theme: appCupertinoTheme.copyWith(brightness: brightness),
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: brightness == Brightness.dark
|
||||
? appDarkTheme()
|
||||
: appLightTheme(),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
Future<BuildContext> _pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
bool? inactive,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(1000, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
_header(
|
||||
cupertino: cupertino,
|
||||
color: color,
|
||||
brightness: brightness,
|
||||
inactive: inactive,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return tester.element(find.byType(ChatThreadHeader));
|
||||
}
|
||||
|
||||
Color? _titleFill(WidgetTester tester) => tester
|
||||
.widget<GlassPill>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byKey(const Key('chat-info')),
|
||||
matching: find.byType(GlassPill),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.fill;
|
||||
|
||||
Color? _textColor(WidgetTester tester, String text) =>
|
||||
tester.renderObject<RenderParagraph>(find.text(text)).text.style?.color;
|
||||
|
||||
Color? _iconIn(WidgetTester tester, Finder control) => IconTheme.of(
|
||||
tester.element(find.descendant(of: control, matching: find.byType(Icon))),
|
||||
).color;
|
||||
|
||||
final _files = find.byType(ChatBarAction);
|
||||
final _back = find.byKey(const Key('chat-back'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: a chat with no colour keeps the neutral bar', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(tester, cupertino: cupertino);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
|
||||
expect(find.byType(ChatBarTintScope), findsNothing);
|
||||
expect(_titleFill(tester), isNull);
|
||||
for (final pill in tester.widgetList<GlassPill>(find.byType(GlassPill))) {
|
||||
expect(pill.fill, isNull);
|
||||
}
|
||||
final neutral = cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
expect(_textColor(tester, 'Model'), isSameColorAs(neutral));
|
||||
});
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('$host ${brightness.name}: a coloured chat tints every '
|
||||
'glass piece and takes its foreground', (tester) async {
|
||||
final context = await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
color: 'teal',
|
||||
brightness: brightness,
|
||||
);
|
||||
final dark = brightness == Brightness.dark;
|
||||
final shade = chatColorShade(context, 'teal')!;
|
||||
final raised = cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final expected = ChatBarTint.from(
|
||||
shade: shade,
|
||||
raised: raised,
|
||||
dark: dark,
|
||||
);
|
||||
expect(expected.fill.a, closeTo(GlassPill.fillOpacity, 1e-6));
|
||||
expect(
|
||||
expected.fill.withValues(alpha: 1),
|
||||
Color.alphaBlend(
|
||||
shade.withValues(alpha: dark ? chatBarTintDark : chatBarTintLight),
|
||||
raised,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
expected.foreground,
|
||||
chatSeededScheme(shade, dark: dark).onPrimaryContainer,
|
||||
);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
// Back, title, the control island and the Files island.
|
||||
final pills = tester.widgetList<GlassPill>(find.byType(GlassPill));
|
||||
expect(pills.length, greaterThanOrEqualTo(4));
|
||||
for (final pill in pills) {
|
||||
expect(pill.fill, expected.fill);
|
||||
}
|
||||
expect(_titleFill(tester), expected.fill);
|
||||
expect(_textColor(tester, 'Colour chat'), expected.foreground);
|
||||
expect(_textColor(tester, 'Model'), expected.foreground);
|
||||
expect(_iconIn(tester, _files), expected.foreground);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('$host: an inactive split pane fades its bar tint to half', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
color: 'orange',
|
||||
inactive: true,
|
||||
);
|
||||
final shade = chatColorShade(context, 'orange')!;
|
||||
final raised = cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final faded = ChatBarTint.from(
|
||||
shade: shade,
|
||||
raised: raised,
|
||||
dark: false,
|
||||
inactive: true,
|
||||
);
|
||||
expect(
|
||||
faded.fill.withValues(alpha: 1),
|
||||
Color.alphaBlend(
|
||||
shade.withValues(alpha: chatBarTintLight * chatBarInactiveFade),
|
||||
raised,
|
||||
),
|
||||
);
|
||||
expect(_titleFill(tester), faded.fill);
|
||||
|
||||
// The same pane turning active takes the full tint.
|
||||
await tester.pumpWidget(
|
||||
_header(cupertino: cupertino, color: 'orange', inactive: false),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final full = ChatBarTint.from(shade: shade, raised: raised, dark: false);
|
||||
expect(_titleFill(tester), full.fill);
|
||||
expect(full.fill, isNot(faded.fill));
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Material: bar icons take the seeded onPrimaryContainer', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(tester, cupertino: false, color: 'purple');
|
||||
final shade = chatColorShade(context, 'purple')!;
|
||||
final foreground = ColorScheme.fromSeed(
|
||||
seedColor: shade,
|
||||
).onPrimaryContainer;
|
||||
expect(_iconIn(tester, _back), foreground);
|
||||
expect(_iconIn(tester, _files), foreground);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino: the colour is the bar tint, so Back and Files take '
|
||||
'it natively', (tester) async {
|
||||
final context = await _pump(tester, cupertino: true, color: 'purple');
|
||||
final tint = chatBarTintOf(context, 'purple')!;
|
||||
final inBar = tester.element(_files);
|
||||
expect(CupertinoTheme.of(inBar).primaryColor, tint.foreground);
|
||||
expect(_iconIn(tester, _files), tint.foreground);
|
||||
// The stock Back draws its chevron in its text style's colour.
|
||||
final chevron = tester.element(
|
||||
find.descendant(of: _back, matching: find.byType(RichText)).first,
|
||||
);
|
||||
expect(
|
||||
DefaultTextStyle.of(chevron).style.color,
|
||||
isSameColorAs(tint.foreground),
|
||||
);
|
||||
// Outside the bar the theme's tint is untouched.
|
||||
expect(
|
||||
CupertinoTheme.of(context).primaryColor,
|
||||
isNot(tint.foreground),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/composer_focus_ring.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
/// The focus ring wrapping the composer pill: its outer glow and inner ring.
|
||||
({Color glow, BorderSide side}) _ring(WidgetTester tester) {
|
||||
/// The focus ring wrapping the composer pill: its stroke and (absent) glow.
|
||||
({Decoration? decoration, BorderSide side}) _ring(WidgetTester tester) {
|
||||
final container = tester.widget<AnimatedContainer>(
|
||||
find.byKey(const Key('chat-composer-focus-ring')),
|
||||
);
|
||||
final glow = (container.decoration! as ShapeDecoration).shadows!.single;
|
||||
final shape = (container.foregroundDecoration! as ShapeDecoration).shape;
|
||||
return (glow: glow.color, side: (shape as RoundedRectangleBorder).side);
|
||||
return (
|
||||
decoration: container.decoration,
|
||||
side: (shape as RoundedRectangleBorder).side,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _focusField(WidgetTester tester) async {
|
||||
@@ -27,17 +30,20 @@ void main() {
|
||||
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
testWidgets('unfocused composer draws no ring or glow', (tester) async {
|
||||
testWidgets('unfocused composer draws no ring and never a glow', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final ring = _ring(tester);
|
||||
expect(ring.side.color.a, 0);
|
||||
expect(ring.glow.a, 0);
|
||||
expect(ring.decoration, isNull);
|
||||
expect(ring.side.width, ComposerFocusRing.ringWidth);
|
||||
expect(ComposerFocusRing.ringWidth, 2);
|
||||
});
|
||||
|
||||
testWidgets('focused composer takes the primary colour as its ring', (
|
||||
testWidgets('focused composer rings in the primary colour, opaque', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
@@ -48,15 +54,12 @@ void main() {
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
).colorScheme.primary;
|
||||
final ring = _ring(tester);
|
||||
expect(
|
||||
ring.side.color,
|
||||
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
expect(ring.glow, primary.withValues(alpha: ComposerFocusRing.glowOpacity));
|
||||
expect(ring.side.width, ComposerFocusRing.ringWidth);
|
||||
expect(ring.side.color, primary);
|
||||
expect(ring.side.color.a, 1);
|
||||
expect(ring.decoration, isNull);
|
||||
});
|
||||
|
||||
testWidgets('a coloured chat lends its own shade to the ring', (
|
||||
testWidgets('a coloured chat rings in its seeded scheme primary', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
@@ -65,14 +68,13 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await _focusField(tester);
|
||||
|
||||
final teal = chatColorShade(
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
'teal',
|
||||
)!;
|
||||
expect(
|
||||
_ring(tester).side.color,
|
||||
teal.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
final context = tester.element(find.byKey(const Key('chat-composer-field')));
|
||||
final teal = chatColorShade(context, 'teal')!;
|
||||
final expected = chatSeededScheme(teal, dark: false).primary;
|
||||
expect(_ring(tester).side.color, expected);
|
||||
expect(chatFocusRingColor(context, 'teal'), expected);
|
||||
// Not the raw shade: tone 40 of the hue, so it keeps 3:1 on the page.
|
||||
expect(expected, isNot(teal));
|
||||
});
|
||||
|
||||
testWidgets('the ring fades out again when focus leaves', (tester) async {
|
||||
@@ -88,7 +90,7 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(_ring(tester).side.color.a, 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_ring(tester).glow.a, 0);
|
||||
expect(_ring(tester).side.color.a, 0);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino composer rings in the theme primary colour', (
|
||||
@@ -101,9 +103,6 @@ void main() {
|
||||
final primary = CupertinoTheme.of(
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
).primaryColor;
|
||||
expect(
|
||||
_ring(tester).side.color,
|
||||
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
expect(_ring(tester).side.color, isSameColorAs(primary));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user