Merge main (High contrast) into Glass; Glass snaps live switches
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import '../ui/theme/design_focus_ring.dart';
|
||||
import '../ui/adaptive/window_margins.dart';
|
||||
import '../ui/theme/app_design_controller.dart';
|
||||
import '../ui/theme/glass_backdrop.dart';
|
||||
@@ -90,9 +91,11 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _scaled(BuildContext context, Widget? child) => UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
static Widget _scaled(BuildContext context, Widget? child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../ui/theme/design_focus_ring.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -223,9 +224,11 @@ class _DetachedWindowAppState extends State<DetachedWindowApp> {
|
||||
: '${_title.value} · Pipelines',
|
||||
scaffoldMessengerKey: appScaffoldMessengerKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
builder: (context, child) => UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
),
|
||||
theme: designs.design.light(fontFamily: fonts.family),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../ui/theme/design_focus_ring.dart';
|
||||
import 'dart:async';
|
||||
import '../core/servers/chat/chat_server_pool.dart';
|
||||
import '../ui/adaptive/window_margins.dart';
|
||||
@@ -385,9 +386,11 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
listenable: Listenable.merge([fonts, designs]),
|
||||
builder: (context, _) => MaterialApp(
|
||||
title: 'Pipelines',
|
||||
builder: (context, child) => UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
),
|
||||
theme: designs.design.light(fontFamily: fonts.family),
|
||||
|
||||
@@ -70,8 +70,12 @@ class ChatBarTint {
|
||||
}
|
||||
|
||||
/// 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].
|
||||
/// with no colour (its bar stays neutral), or under a design with a
|
||||
/// contrast floor ([AppDesignTokens.minContrast]), which marks a chat's
|
||||
/// colour with bars and outlines, never a tinted fill. Reads
|
||||
/// [ChatPaneActivity].
|
||||
ChatBarTint? chatBarTintOf(BuildContext context, String? name) {
|
||||
if (AppDesignTokens.of(context).minContrast != null) return null;
|
||||
final shade = chatColorShade(context, name);
|
||||
if (shade == null) return null;
|
||||
return ChatBarTint.from(
|
||||
|
||||
@@ -115,19 +115,27 @@ class _ChatSendUsageRingState extends State<ChatSendUsageRing> {
|
||||
|
||||
ChatUsageRingPainter _painter(BuildContext context, ChatUsageRing ring) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
// A design with a contrast floor draws the ring solid: the quiet arc
|
||||
// in the secondary ink over a track in the rule colour.
|
||||
final solid = tokens.minContrast != null;
|
||||
return ChatUsageRingPainter(
|
||||
fraction: ring.fraction,
|
||||
color: switch (ring.tone) {
|
||||
ChatUsageRingTone.quiet => scheme.onSurfaceVariant.withValues(
|
||||
alpha: .45,
|
||||
),
|
||||
ChatUsageRingTone.quiet =>
|
||||
solid
|
||||
? scheme.onSurfaceVariant
|
||||
: scheme.onSurfaceVariant.withValues(alpha: .45),
|
||||
ChatUsageRingTone.warning => scheme.tertiary,
|
||||
ChatUsageRingTone.urgent => scheme.error,
|
||||
},
|
||||
track: scheme.outlineVariant.withValues(alpha: .35),
|
||||
track: solid
|
||||
? scheme.outlineVariant
|
||||
: scheme.outlineVariant.withValues(alpha: .35),
|
||||
circle: chatSendButtonDiameter(context),
|
||||
// A design with square-ish corners frames its square send button.
|
||||
cornerRadius: AppDesignTokens.of(context).radius,
|
||||
cornerRadius: tokens.radius,
|
||||
stroke: tokens.ringStroke,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -160,6 +168,7 @@ class ChatUsageRingPainter extends CustomPainter {
|
||||
required this.track,
|
||||
required this.circle,
|
||||
this.cornerRadius,
|
||||
this.stroke = 2,
|
||||
});
|
||||
|
||||
final double fraction;
|
||||
@@ -171,7 +180,8 @@ class ChatUsageRingPainter extends CustomPainter {
|
||||
/// round button. The ring then follows a rounded square instead.
|
||||
final double? cornerRadius;
|
||||
|
||||
static const double stroke = 2;
|
||||
/// The ring's width ([AppDesignTokens.ringStroke]).
|
||||
final double stroke;
|
||||
|
||||
/// A clear gap between the button and the ring, so the ring reads as its
|
||||
/// own feature.
|
||||
@@ -245,6 +255,7 @@ class ChatUsageRingPainter extends CustomPainter {
|
||||
@override
|
||||
bool shouldRepaint(ChatUsageRingPainter old) =>
|
||||
old.cornerRadius != cornerRadius ||
|
||||
old.stroke != stroke ||
|
||||
old.fraction != fraction ||
|
||||
old.color != color ||
|
||||
old.track != track ||
|
||||
|
||||
@@ -330,9 +330,13 @@ class ChatStackColumnItems extends StatelessWidget {
|
||||
decoration: ShapeDecoration(
|
||||
color: tokens.flat || header ? null : scheme.primaryContainer,
|
||||
shape: chatStackShape(tokens).copyWith(
|
||||
side: tokens.flat
|
||||
? BorderSide(color: scheme.primary.withValues(alpha: .55))
|
||||
: BorderSide.none,
|
||||
// A design with a contrast floor frames it in the full
|
||||
// accent at its own stroke.
|
||||
side: !tokens.flat
|
||||
? BorderSide.none
|
||||
: tokens.minContrast != null
|
||||
? BorderSide(color: scheme.primary, width: tokens.stroke)
|
||||
: BorderSide(color: scheme.primary.withValues(alpha: .55)),
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
|
||||
@@ -206,7 +206,10 @@ class ChatStackLabel extends StatelessWidget {
|
||||
);
|
||||
final color = this.color;
|
||||
final dark = theme.brightness == Brightness.dark;
|
||||
final fill = color == null
|
||||
// A design with a contrast floor marks the chat's colour with a bold
|
||||
// outline rather than a tint.
|
||||
final outlined = color != null && tokens.minContrast != null;
|
||||
final fill = color == null || outlined
|
||||
? base
|
||||
: Color.alphaBlend(color.withValues(alpha: dark ? .22 : .14), base);
|
||||
final style = (theme.textTheme.labelLarge ?? const TextStyle()).copyWith(
|
||||
@@ -215,7 +218,10 @@ class ChatStackLabel extends StatelessWidget {
|
||||
);
|
||||
final rest = ShapeDecoration(
|
||||
color: fill,
|
||||
shape: _labelShape(tokens),
|
||||
shape: _labelShape(
|
||||
tokens,
|
||||
outlined ? BorderSide(color: color, width: 3) : null,
|
||||
),
|
||||
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
||||
);
|
||||
return chatStackLifted(
|
||||
@@ -262,8 +268,8 @@ class ChatStackLabel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
OutlinedBorder _labelShape(AppDesignTokens tokens) {
|
||||
final side = tokens.frameSide ?? BorderSide.none;
|
||||
OutlinedBorder _labelShape(AppDesignTokens tokens, [BorderSide? outline]) {
|
||||
final side = outline ?? tokens.frameSide ?? BorderSide.none;
|
||||
final r = tokens.radius;
|
||||
return r == null
|
||||
? StadiumBorder(side: side)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../../../ui/theme/high_contrast_palette.dart';
|
||||
import '../../domain/chat_colors.dart';
|
||||
|
||||
/// The host's own shade for a chat colour name, tuned for the current
|
||||
@@ -8,10 +9,20 @@ import '../../domain/chat_colors.dart';
|
||||
/// a lighter one on dark), so the mark keeps its contrast in both, quietened
|
||||
/// to the design's [AppDesignTokens.chatColorSaturation] (Paper's ink tones).
|
||||
/// Null for no (or an unknown) colour.
|
||||
///
|
||||
/// A design with [AppDesignTokens.minContrast] (High contrast) gets
|
||||
/// the shade lightened or darkened until it reaches that contrast against
|
||||
/// its page, so a chat's bar reads as plainly as text.
|
||||
Color? chatColorShade(BuildContext context, String? name) {
|
||||
final shade = _materialShade(context, name);
|
||||
if (shade == null) return null;
|
||||
final saturation = AppDesignTokens.of(context).chatColorSaturation;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final contrast = tokens.minContrast;
|
||||
if (contrast != null) {
|
||||
final page = Theme.of(context).scaffoldBackgroundColor;
|
||||
return colorWithContrast(shade, page, contrast);
|
||||
}
|
||||
final saturation = tokens.chatColorSaturation;
|
||||
if (saturation >= 1) return shade;
|
||||
final hsl = HSLColor.fromColor(shade);
|
||||
return hsl.withSaturation(hsl.saturation * saturation).toColor();
|
||||
|
||||
@@ -161,7 +161,7 @@ class ChatSessionRow extends StatelessWidget {
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
child: _Star(color: accent),
|
||||
child: const _Star(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -169,11 +169,16 @@ class ChatSessionRow extends StatelessWidget {
|
||||
),
|
||||
timeWidget: updatedAt == null
|
||||
? null
|
||||
: DefaultTextStyle.merge(
|
||||
style: TextStyle(
|
||||
color: unread ? accent : chatMetadataForeground(context),
|
||||
// Coloured from the row's own theme, as the star is.
|
||||
: Builder(
|
||||
builder: (context) => DefaultTextStyle.merge(
|
||||
style: TextStyle(
|
||||
color: unread
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: chatMetadataForeground(context),
|
||||
),
|
||||
child: RelativeTimeLabel(instant: updatedAt),
|
||||
),
|
||||
child: RelativeTimeLabel(instant: updatedAt),
|
||||
),
|
||||
// `Closed` leads the line of a closed chat, then the model and folder.
|
||||
subtitle: ChatSessionSubtitle(
|
||||
@@ -224,14 +229,15 @@ DateTime? _chatSessionInstant(Object? updatedAt) {
|
||||
}
|
||||
|
||||
/// As tall as the title's text, so it follows text scaling.
|
||||
/// The star in the accent of the row's own theme (an inverted open row
|
||||
/// draws under its opposite-brightness theme).
|
||||
class _Star extends StatelessWidget {
|
||||
const _Star({required this.color});
|
||||
|
||||
final Color color;
|
||||
const _Star();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = DefaultTextStyle.of(context).style.fontSize ?? 14;
|
||||
final color = Theme.of(context).colorScheme.primary;
|
||||
return Icon(
|
||||
Icons.star,
|
||||
key: const Key('chat-row-starred'),
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../../domain/chat_tool_calls.dart';
|
||||
import '../../../domain/chat_turn_activity.dart';
|
||||
import '../chat_response_pending.dart';
|
||||
import 'boxed_quote.dart';
|
||||
|
||||
/// How many of a turn's calls a boxed block lists; earlier ones fold into
|
||||
/// one "earlier" row (every call stays in the details dialog).
|
||||
const int boxedActivityMaxCalls = 6;
|
||||
|
||||
/// A tool call's status in words, never by colour alone.
|
||||
enum BoxedToolStatus {
|
||||
done('Done', Icons.check),
|
||||
failed('Failed', Icons.close),
|
||||
running('Running', Icons.more_horiz);
|
||||
|
||||
const BoxedToolStatus(this.word, this.icon);
|
||||
|
||||
final String word;
|
||||
final IconData icon;
|
||||
|
||||
static BoxedToolStatus of(JsonMap call) => chatToolFailed(call)
|
||||
? failed
|
||||
: chatToolRunning(call)
|
||||
? running
|
||||
: done;
|
||||
}
|
||||
|
||||
/// A turn's activity under a boxed transcript (High contrast): a bordered
|
||||
/// block with one row per tool call, each led by its status as an icon and
|
||||
/// a word ("Done", "Failed", "Running") in a status colour that reads at
|
||||
/// 7:1, then the tool and what it acted on. While the turn runs a live row
|
||||
/// says what it is doing. The block is one button that opens the activity
|
||||
/// details, like the Default design's line.
|
||||
class BoxedActivityRows extends StatelessWidget {
|
||||
const BoxedActivityRows({
|
||||
super.key,
|
||||
required this.data,
|
||||
required this.status,
|
||||
required this.streaming,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final ChatTurnActivityData data;
|
||||
|
||||
/// The turn's one-line status (with its running seconds while streaming).
|
||||
final String status;
|
||||
final bool streaming;
|
||||
final VoidCallback onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final style = theme.textTheme.bodyMedium!.copyWith(color: scheme.onSurface);
|
||||
final calls = data.tools;
|
||||
final shown = calls.length > boxedActivityMaxCalls
|
||||
? calls.sublist(calls.length - boxedActivityMaxCalls)
|
||||
: calls;
|
||||
final hidden = calls.length - shown.length;
|
||||
final rule = Divider(
|
||||
height: tokens.stroke,
|
||||
thickness: tokens.stroke,
|
||||
color: scheme.outlineVariant,
|
||||
);
|
||||
final rows = <Widget>[
|
||||
if (hidden > 0)
|
||||
_row(
|
||||
context,
|
||||
null,
|
||||
Text(
|
||||
'$hidden earlier tool ${hidden == 1 ? 'use' : 'uses'}',
|
||||
style: style.copyWith(color: scheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
for (final call in shown) _call(context, call, style),
|
||||
if (calls.isEmpty && !streaming)
|
||||
_row(
|
||||
context,
|
||||
data.failed ? BoxedToolStatus.failed : BoxedToolStatus.done,
|
||||
Text(status, style: style),
|
||||
),
|
||||
if (streaming) _live(context, style),
|
||||
];
|
||||
final radius = BorderRadius.circular(tokens.radius ?? 6);
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: '$status, expand for details',
|
||||
excludeSemantics: true,
|
||||
onTap: onOpen,
|
||||
child: Material(
|
||||
key: const Key('chat-boxed-activity'),
|
||||
type: MaterialType.transparency,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: radius,
|
||||
side: BorderSide(color: scheme.outline, width: tokens.stroke),
|
||||
),
|
||||
child: InkWell(
|
||||
key: const Key('chat-turn-activity'),
|
||||
onTap: onOpen,
|
||||
borderRadius: radius,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(tokens.stroke),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (final (index, row) in rows.indexed) ...[
|
||||
if (index > 0) rule,
|
||||
row,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _call(BuildContext context, JsonMap call, TextStyle style) {
|
||||
final detail = chatToolDetail(call);
|
||||
final duration = chatToolDurationMillis(call);
|
||||
return _row(
|
||||
context,
|
||||
BoxedToolStatus.of(call),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: chatToolLabel(call),
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
if (detail != null) TextSpan(text: ' $detail'),
|
||||
if (duration != null)
|
||||
TextSpan(text: ' · ${formatChatToolDuration(duration)}'),
|
||||
],
|
||||
),
|
||||
style: style,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The running row: the pending dots, then what the turn is doing and for
|
||||
/// how long, in the accent.
|
||||
Widget _live(BuildContext context, TextStyle style) {
|
||||
final accent = Theme.of(context).colorScheme.primary;
|
||||
return _row(
|
||||
context,
|
||||
null,
|
||||
Row(
|
||||
children: [
|
||||
ExcludeSemantics(
|
||||
child: DefaultTextStyle.merge(
|
||||
style: TextStyle(color: accent),
|
||||
child: const ChatResponsePending(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
status,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: style.copyWith(color: accent),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// One row: the status word (when there is one) in a column of its own,
|
||||
/// then [body]. At least 44px tall, so the block is a big target.
|
||||
Widget _row(BuildContext context, BoxedToolStatus? status, Widget body) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final ansi = AppDesignTokens.of(context).ansi;
|
||||
final color = switch (status) {
|
||||
BoxedToolStatus.failed => ansi?.red ?? scheme.error,
|
||||
BoxedToolStatus.running => ansi?.yellow ?? scheme.tertiary,
|
||||
BoxedToolStatus.done => ansi?.green ?? scheme.primary,
|
||||
null => scheme.onSurfaceVariant,
|
||||
};
|
||||
final label = theme.textTheme.labelLarge?.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w800,
|
||||
);
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 44),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
boxedQuotePadding,
|
||||
8,
|
||||
boxedQuotePadding,
|
||||
8,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (status != null) ...[
|
||||
// One column for every row's status, as wide as the longest
|
||||
// word, so the tool names line up.
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: _statusWidth(
|
||||
label,
|
||||
MediaQuery.textScalerOf(context),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(status.icon, size: 20, color: color),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
status.word,
|
||||
key: Key('boxed-status-${status.name}'),
|
||||
style: label,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
Expanded(child: body),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final Map<(TextStyle?, TextScaler), double> _statusWidths = {};
|
||||
|
||||
/// The status column's width: the icon, its gap and the widest status word
|
||||
/// in [style] at [scaler], measured once per style and scale.
|
||||
double _statusWidth(TextStyle? style, TextScaler scaler) =>
|
||||
_statusWidths[(style, scaler)] ??= () {
|
||||
var widest = 0.0;
|
||||
for (final status in BoxedToolStatus.values) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: status.word, style: style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: scaler,
|
||||
)..layout();
|
||||
if (painter.width > widest) widest = painter.width;
|
||||
painter.dispose();
|
||||
}
|
||||
return 20 + 6 + widest.ceilToDouble();
|
||||
}();
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../sessions/chat_color_palette.dart';
|
||||
import '../chat_message_bubble.dart';
|
||||
|
||||
/// The width of the bar in the chat's colour along a boxed turn's leading
|
||||
/// edge.
|
||||
const double boxedQuoteBar = 6;
|
||||
|
||||
/// The padding inside a boxed turn, after its bar.
|
||||
const double boxedQuotePadding = 12;
|
||||
|
||||
/// Where a boxed turn's text starts, from the row's edge: the footer under
|
||||
/// it (its delivery line and time) starts here too.
|
||||
const double boxedQuoteTextInset = boxedQuoteBar + boxedQuotePadding;
|
||||
|
||||
/// The words of the label above the operator's boxed turn.
|
||||
const String boxedQuoteLabel = 'You';
|
||||
|
||||
/// The operator's turn under a boxed transcript (High contrast): a "You"
|
||||
/// label, then the words in a box framed in the ink at the design's stroke,
|
||||
/// with a thick bar in the chat's colour (the ink for a chat with none) on
|
||||
/// its leading edge. Painted in one pass: no clip layer per turn.
|
||||
class BoxedQuote extends StatelessWidget {
|
||||
const BoxedQuote({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final bar = chatColorShade(context, ChatBubbleColor.of(context));
|
||||
return Material(
|
||||
key: const Key('chat-boxed-quote'),
|
||||
type: MaterialType.transparency,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ExcludeSemantics(
|
||||
child: SelectionContainer.disabled(
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(bottom: 4),
|
||||
child: Text(
|
||||
boxedQuoteLabel,
|
||||
key: const Key('chat-boxed-quote-label'),
|
||||
style: theme.textTheme.labelLarge?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
CustomPaint(
|
||||
foregroundPainter: BoxedFramePainter(
|
||||
frame: scheme.outline,
|
||||
bar: bar ?? scheme.onSurface,
|
||||
stroke: tokens.stroke,
|
||||
radius: tokens.radius ?? 6,
|
||||
barWidth: boxedQuoteBar,
|
||||
textDirection: Directionality.of(context),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
boxedQuoteTextInset,
|
||||
10,
|
||||
boxedQuotePadding,
|
||||
10,
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A rounded frame of [stroke] in [frame], with a [barWidth] bar in [bar]
|
||||
/// along its leading edge inside the corners. Drawn with canvas clips only,
|
||||
/// so a list of them adds no layers.
|
||||
class BoxedFramePainter extends CustomPainter {
|
||||
const BoxedFramePainter({
|
||||
required this.frame,
|
||||
required this.bar,
|
||||
required this.stroke,
|
||||
required this.radius,
|
||||
required this.textDirection,
|
||||
this.barWidth = 0,
|
||||
});
|
||||
|
||||
final Color frame;
|
||||
final Color bar;
|
||||
final double stroke;
|
||||
final double radius;
|
||||
final double barWidth;
|
||||
final TextDirection textDirection;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final outer = RRect.fromRectAndRadius(
|
||||
Offset.zero & size,
|
||||
Radius.circular(radius),
|
||||
);
|
||||
if (barWidth > 0) {
|
||||
final rect = textDirection == TextDirection.ltr
|
||||
? Rect.fromLTWH(0, 0, barWidth, size.height)
|
||||
: Rect.fromLTWH(size.width - barWidth, 0, barWidth, size.height);
|
||||
canvas
|
||||
..save()
|
||||
..clipRRect(outer)
|
||||
..drawRect(rect, Paint()..color = bar)
|
||||
..restore();
|
||||
}
|
||||
canvas.drawRRect(
|
||||
outer.deflate(stroke / 2),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = stroke
|
||||
..color = frame,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(BoxedFramePainter old) =>
|
||||
old.frame != frame ||
|
||||
old.bar != bar ||
|
||||
old.stroke != stroke ||
|
||||
old.radius != radius ||
|
||||
old.barWidth != barWidth ||
|
||||
old.textDirection != textDirection;
|
||||
}
|
||||
@@ -29,10 +29,11 @@ class ChatAttachmentGallery extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => Wrap(
|
||||
key: const Key('chat-attachment-gallery'),
|
||||
alignment:
|
||||
AppDesignTokens.of(context).transcript == TranscriptStyle.manuscript
|
||||
? WrapAlignment.start
|
||||
: WrapAlignment.end,
|
||||
alignment: switch (AppDesignTokens.of(context).transcript) {
|
||||
TranscriptStyle.manuscript ||
|
||||
TranscriptStyle.boxed => WrapAlignment.start,
|
||||
_ => WrapAlignment.end,
|
||||
},
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
|
||||
@@ -105,17 +105,28 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
key: const Key('chat-automated-prompt'),
|
||||
color: glass?.card ?? scheme.surfaceContainerLow,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
// A glass design's note is a small glass card with a light top
|
||||
// edge.
|
||||
shape: glass == null
|
||||
// A boxed transcript frames it in the design's corners and
|
||||
// stroke, in the secondary ink, so it reads apart from the
|
||||
// operator's own boxes framed in the ink.
|
||||
shape: transcript == TranscriptStyle.boxed
|
||||
? RoundedRectangleBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
borderRadius: tokens.corners(BorderRadius.zero),
|
||||
side: BorderSide(
|
||||
color: scheme.outlineVariant,
|
||||
width: tokens.stroke,
|
||||
),
|
||||
)
|
||||
: GlassBorder(
|
||||
// A glass design's note is a small glass card with a
|
||||
// light top edge.
|
||||
: glass != null
|
||||
? GlassBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
highlight: glass.highlight,
|
||||
edge: glass.edge,
|
||||
)
|
||||
: RoundedRectangleBorder(
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
@@ -147,7 +158,7 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
TranscriptStyle.prompt => 8 + terminalGlyphColumn(context),
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.cells => notebookCellTextInset,
|
||||
TranscriptStyle.bubbles => 14.0,
|
||||
TranscriptStyle.bubbles || TranscriptStyle.boxed => 14.0,
|
||||
};
|
||||
return ChatHoverRegion(
|
||||
child: Column(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../sessions/chat_color_palette.dart';
|
||||
import 'boxed/boxed_quote.dart';
|
||||
import 'notebook/notebook_input_cell.dart';
|
||||
import 'paper/paper_quote.dart';
|
||||
import 'terminal/terminal_prompt_line.dart';
|
||||
@@ -52,6 +53,8 @@ class ChatUserBubble extends StatelessWidget {
|
||||
return TerminalPromptLine(child: child);
|
||||
case TranscriptStyle.manuscript:
|
||||
return PaperQuote(child: child);
|
||||
case TranscriptStyle.boxed:
|
||||
return BoxedQuote(child: child);
|
||||
case TranscriptStyle.cells:
|
||||
return NotebookInputCell(child: child);
|
||||
case TranscriptStyle.bubbles:
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'chat_link_text.dart';
|
||||
import 'chat_message_bubble.dart';
|
||||
import 'chat_turn_activity_view.dart';
|
||||
import 'native_disclosure.dart';
|
||||
import 'boxed/boxed_quote.dart';
|
||||
import 'notebook/notebook_cell_frame.dart';
|
||||
import 'notebook/notebook_gutter.dart';
|
||||
import 'notebook/notebook_tool_cell.dart';
|
||||
@@ -122,7 +123,9 @@ class ChatMessageView extends StatelessWidget {
|
||||
padding: cells
|
||||
? EdgeInsets.only(top: user ? 6 : 3, bottom: user ? 3 : 6)
|
||||
: EdgeInsets.symmetric(
|
||||
vertical: transcript == TranscriptStyle.manuscript
|
||||
vertical:
|
||||
transcript == TranscriptStyle.manuscript ||
|
||||
transcript == TranscriptStyle.boxed
|
||||
? 12
|
||||
: tokens.density.space(6),
|
||||
),
|
||||
@@ -229,11 +232,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
children: [
|
||||
if (thumbnails.isNotEmpty)
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: transcript == TranscriptStyle.manuscript
|
||||
? paperQuoteTextInset
|
||||
: 0,
|
||||
),
|
||||
padding: EdgeInsetsDirectional.only(start: _quoteInset(transcript)),
|
||||
child: ChatAttachmentGallery(
|
||||
parts: thumbnails,
|
||||
images: images ?? _inlineImages,
|
||||
@@ -252,6 +251,7 @@ class ChatMessageView extends StatelessWidget {
|
||||
start: switch (transcript) {
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.cells => notebookCellTextInset,
|
||||
TranscriptStyle.boxed => boxedQuoteTextInset,
|
||||
_ => 0,
|
||||
},
|
||||
),
|
||||
@@ -272,6 +272,14 @@ class ChatMessageView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// Where the text of the operator's turn starts under [transcript]: the
|
||||
/// thumbnails above it and the footer under it start there too.
|
||||
static double _quoteInset(TranscriptStyle transcript) => switch (transcript) {
|
||||
TranscriptStyle.manuscript => paperQuoteTextInset,
|
||||
TranscriptStyle.boxed => boxedQuoteTextInset,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
/// A prompt the agent or the server sent: its card, with the delivery line
|
||||
/// and time beneath.
|
||||
Widget _automatedTurn(ChatPromptOrigin origin, List<Widget> content) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_response_pending.dart';
|
||||
import 'chat_turn_activity_details.dart';
|
||||
import 'chat_turn_chip.dart';
|
||||
import 'boxed/boxed_activity_rows.dart';
|
||||
import 'notebook/notebook_tool_cells.dart';
|
||||
import 'paper/paper_activity_note.dart';
|
||||
import 'terminal/terminal_activity_rows.dart';
|
||||
@@ -143,6 +144,13 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
failed: data.failed,
|
||||
onOpen: _open,
|
||||
);
|
||||
case TranscriptStyle.boxed:
|
||||
return BoxedActivityRows(
|
||||
data: data,
|
||||
status: label,
|
||||
streaming: widget.streaming,
|
||||
onOpen: _open,
|
||||
);
|
||||
case TranscriptStyle.cells:
|
||||
return NotebookToolCells(
|
||||
data: data,
|
||||
|
||||
@@ -73,7 +73,11 @@ class GraphCanvasStyle {
|
||||
color: secondary,
|
||||
),
|
||||
edgeColor: theme.colorScheme.outline,
|
||||
edgeWidth: theme.dividerTheme.thickness ?? 1,
|
||||
// A design with heavier frames draws its edges as heavy as them.
|
||||
edgeWidth: [
|
||||
theme.dividerTheme.thickness ?? 1,
|
||||
AppDesignTokens.of(context).stroke,
|
||||
].reduce((a, b) => a > b ? a : b),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,19 @@ class GraphStageNode extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// A design that inverts its selection draws the selected node, content
|
||||
// and all, under its opposite-brightness theme on that theme's page.
|
||||
if (selected &&
|
||||
AppDesignTokens.of(context).selectedRow == SelectedRowStyle.inverted) {
|
||||
return Theme(
|
||||
data: AppDesignTokens.inverseTheme(Theme.of(context)),
|
||||
child: Builder(builder: _build),
|
||||
);
|
||||
}
|
||||
return _build(context);
|
||||
}
|
||||
|
||||
Widget _build(BuildContext context) {
|
||||
final content = ExcludeSemantics(child: _content(context));
|
||||
void onPressed() => onSelected(node.key);
|
||||
final control = MergeSemantics(
|
||||
@@ -74,6 +87,8 @@ class GraphStageNode extends StatelessWidget {
|
||||
VoidCallback onPressed,
|
||||
Widget content,
|
||||
) {
|
||||
final inverted =
|
||||
AppDesignTokens.of(context).selectedRow == SelectedRowStyle.inverted;
|
||||
// A dense design draws a smaller node: half the inset and a 32px
|
||||
// least height on a pointer device (40px on touch).
|
||||
final density = AppDesignTokens.of(context).density;
|
||||
@@ -107,6 +122,7 @@ class GraphStageNode extends StatelessWidget {
|
||||
);
|
||||
return selected
|
||||
? Card.filled(
|
||||
color: inverted ? Theme.of(context).colorScheme.surface : null,
|
||||
margin: EdgeInsets.zero,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: body,
|
||||
|
||||
@@ -62,9 +62,7 @@ class SettingsGroup extends StatelessWidget {
|
||||
borderRadius: tokens.corners(
|
||||
BorderRadius.circular(settingsGroupRadius),
|
||||
),
|
||||
side: tokens.frame == null
|
||||
? BorderSide.none
|
||||
: BorderSide(color: tokens.frame!),
|
||||
side: tokens.frameSide ?? BorderSide.none,
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
|
||||
@@ -7,10 +7,12 @@ import 'window_kind.dart';
|
||||
const double windowCornerRadius = 12;
|
||||
|
||||
/// A floating window's corners under the design at [context]:
|
||||
/// [windowCornerRadius], or a dense design's own corners, or a glass
|
||||
/// design's grown ones.
|
||||
/// [windowCornerRadius], a design's own window radius (High contrast's), or
|
||||
/// a dense design's own corners, or a glass design's grown ones.
|
||||
BorderRadius windowCorners(BuildContext context) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final radius = tokens.windowRadius;
|
||||
if (radius != null) return BorderRadius.circular(radius);
|
||||
const designed = BorderRadius.all(Radius.circular(windowCornerRadius));
|
||||
return tokens.glass == null
|
||||
? tokens.denseCorners(designed)
|
||||
@@ -157,14 +159,20 @@ class WindowOutline extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
// A design with heavier frames draws its own (High contrast's 2px of
|
||||
// the ink); the others keep the hairline.
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final side = tokens.stroke > 1
|
||||
? tokens.frameSide ?? BorderSide(color: colors.outlineVariant)
|
||||
: BorderSide(color: colors.outlineVariant);
|
||||
final corners = windowCorners(context);
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
final glass = tokens.glass;
|
||||
return IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
// A glass window's edge catches the light along its title bar.
|
||||
decoration: glass == null
|
||||
? BoxDecoration(
|
||||
border: Border.all(color: colors.outlineVariant),
|
||||
border: Border.fromBorderSide(side),
|
||||
borderRadius: corners,
|
||||
)
|
||||
: ShapeDecoration(
|
||||
|
||||
@@ -90,7 +90,7 @@ class GlassPill extends StatelessWidget {
|
||||
final border = shape.copyWith(
|
||||
side: BorderSide(
|
||||
color: faded(edge, solid ? 1 : 0.6),
|
||||
width: flat ? 1 : 0.5,
|
||||
width: flat ? tokens.stroke : 0.5,
|
||||
),
|
||||
);
|
||||
Widget content = Material(type: MaterialType.transparency, child: child);
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
|
||||
/// Whether this runs on a desktop platform (macOS, Linux, Windows),
|
||||
/// including a desktop browser. Hover and click targets there hug their
|
||||
/// content; phones and tablets keep full-width touch rows. Uses the device's
|
||||
/// platform, not the theme's: web themes are pinned to Android.
|
||||
/// platform, not the theme's: web themes are pinned to Android. A design
|
||||
/// with [AppDesignTokens.largeTargets] (High contrast) keeps touch targets
|
||||
/// on a desktop too.
|
||||
bool prefersCompactHitTargets(BuildContext context) =>
|
||||
!AppDesignTokens.of(context).largeTargets &&
|
||||
switch (defaultTargetPlatform) {
|
||||
TargetPlatform.macOS ||
|
||||
TargetPlatform.linux ||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/high_contrast_palette.dart';
|
||||
|
||||
/// The leading circle every list row uses, as large as a native contact
|
||||
/// avatar ([CircleAvatar]'s default).
|
||||
@@ -51,14 +52,23 @@ class AppListAvatar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final mark = foreground ?? Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
var mark = foreground ?? Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
// A design with a contrast floor keeps the mark (and its frame) at it.
|
||||
final floor = tokens.minContrast;
|
||||
if (floor != null) {
|
||||
mark = colorWithContrast(
|
||||
mark,
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
floor,
|
||||
);
|
||||
}
|
||||
final fill =
|
||||
background ??
|
||||
(foreground == null
|
||||
? Theme.of(context).colorScheme.surfaceContainerHighest
|
||||
: mark.withValues(alpha: 0.14));
|
||||
// The mark keeps the same proportion of the circle at every density.
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final size = tokens.density.avatarSize;
|
||||
final scale = size / kAppListAvatarSize;
|
||||
final initialStyle =
|
||||
@@ -72,7 +82,10 @@ class AppListAvatar extends StatelessWidget {
|
||||
// tinted circle.
|
||||
final decoration = tokens.flat
|
||||
? BoxDecoration(
|
||||
border: Border.all(color: mark.withValues(alpha: 0.55)),
|
||||
border: Border.all(
|
||||
color: floor == null ? mark.withValues(alpha: 0.55) : mark,
|
||||
width: tokens.stroke,
|
||||
),
|
||||
borderRadius: tokens.corners(BorderRadius.zero),
|
||||
)
|
||||
: BoxDecoration(color: fill, shape: BoxShape.circle);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import '../theme/high_contrast_palette.dart';
|
||||
import 'app_list_avatar.dart';
|
||||
import 'app_list_row_glow.dart';
|
||||
|
||||
@@ -131,11 +132,19 @@ class AppListRow extends StatelessWidget {
|
||||
final bool divider;
|
||||
final double compactWidth;
|
||||
|
||||
/// The faint tint an unselected row with [accent] wears over the list.
|
||||
/// The faint tint an unselected row with [accent] wears over the list;
|
||||
/// none under a design that keeps chat colours to bars
|
||||
/// ([AppDesignTokens.minContrast]).
|
||||
static Color? tintFor(BuildContext context, Color? accent) =>
|
||||
accent?.withValues(
|
||||
alpha: Theme.of(context).brightness == Brightness.dark ? 0.12 : 0.07,
|
||||
);
|
||||
AppDesignTokens.of(context).minContrast != null
|
||||
? null
|
||||
: accent?.withValues(
|
||||
alpha: Theme.of(context).brightness == Brightness.dark ? 0.12 : 0.07,
|
||||
);
|
||||
|
||||
/// The width of an inverted open row's bar: thicker, as the fill already
|
||||
/// marks the row.
|
||||
static const double invertedBarWidth = 6;
|
||||
|
||||
/// How strongly a flat design's open row washes its bar colour over the
|
||||
/// page: Terminal's framed row strongly, Paper's unframed wash a little
|
||||
@@ -152,9 +161,18 @@ class AppListRow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rowStyle = AppDesignTokens.of(context).selectedRow;
|
||||
// An inverted design draws every row's content under a theme: the
|
||||
// page's own, or the opposite brightness's for the open row, so its
|
||||
// text, icons and status colours keep their contrast on the inverted
|
||||
// fill. Every row has the Theme, so selecting one keeps its subtree.
|
||||
final invertible = rowStyle == SelectedRowStyle.inverted;
|
||||
final inverted = invertible && selected;
|
||||
final outer = Theme.of(context);
|
||||
final theme = inverted ? AppDesignTokens.inverseTheme(outer) : outer;
|
||||
final styles = _RowStyles.of(
|
||||
context,
|
||||
selected: selected,
|
||||
outer,
|
||||
selected: selected && !inverted,
|
||||
emphasized: emphasized,
|
||||
);
|
||||
final metrics = _RowMetrics.of(context);
|
||||
@@ -191,7 +209,23 @@ class AppListRow extends StatelessWidget {
|
||||
padding: EdgeInsetsDirectional.only(end: avatarGap),
|
||||
child: leading,
|
||||
),
|
||||
Expanded(child: _text(styles, metrics, compact)),
|
||||
Expanded(
|
||||
// Under the row's own Theme the text reads its styles
|
||||
// from it (localized, as Theme.of gives them).
|
||||
child: invertible
|
||||
? Builder(
|
||||
builder: (context) => _text(
|
||||
_RowStyles.of(
|
||||
Theme.of(context),
|
||||
selected: false,
|
||||
emphasized: emphasized,
|
||||
),
|
||||
metrics,
|
||||
compact,
|
||||
),
|
||||
)
|
||||
: _text(styles, metrics, compact),
|
||||
),
|
||||
if (showMenu)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
@@ -204,14 +238,20 @@ class AppListRow extends StatelessWidget {
|
||||
// How the design marks the open row: Material's tonal fill, or
|
||||
// (on a flat design, where a tonal fill is too faint beside tinted
|
||||
// rows) its bar colour washed over the page, stronger, with a
|
||||
// hairline frame in it when the design frames it (below).
|
||||
final rowStyle = AppDesignTokens.of(context).selectedRow;
|
||||
final washed = selected && rowStyle != SelectedRowStyle.tonal;
|
||||
// hairline frame in it when the design frames it (below), or the
|
||||
// ink as the fill (inverted).
|
||||
final washed =
|
||||
selected &&
|
||||
rowStyle != SelectedRowStyle.tonal &&
|
||||
rowStyle != SelectedRowStyle.inverted;
|
||||
final framed = selected && rowStyle == SelectedRowStyle.framed;
|
||||
final frameColor =
|
||||
selectionAccent ??
|
||||
accent ??
|
||||
Theme.of(context).colorScheme.primary;
|
||||
final themed = invertible
|
||||
? Theme(data: theme, child: content)
|
||||
: content;
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
if (rowStyle == SelectedRowStyle.glow && glass != null) {
|
||||
return AppListRowGlow(
|
||||
@@ -221,20 +261,20 @@ class AppListRow extends StatelessWidget {
|
||||
tint: tint,
|
||||
mark: selected || (showAccentBorder && accent != null),
|
||||
surfaceKey: appListRowSurfaceKey,
|
||||
markKey: selected
|
||||
? appListRowSelectionKey
|
||||
: appListRowAccentKey,
|
||||
markKey: selected ? appListRowSelectionKey : appListRowAccentKey,
|
||||
child: InkWell(
|
||||
key: tapKey,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: content,
|
||||
child: themed,
|
||||
),
|
||||
);
|
||||
}
|
||||
final surface = Material(
|
||||
key: appListRowSurfaceKey,
|
||||
color: washed
|
||||
color: inverted
|
||||
? theme.scaffoldBackgroundColor
|
||||
: washed
|
||||
? Color.alphaBlend(
|
||||
frameColor.withValues(
|
||||
alpha: _washAlpha(
|
||||
@@ -254,22 +294,24 @@ class AppListRow extends StatelessWidget {
|
||||
child: metrics.minHeight > 0
|
||||
? ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: metrics.minHeight),
|
||||
child: Center(widthFactor: 1, child: content),
|
||||
child: Center(widthFactor: 1, child: themed),
|
||||
)
|
||||
: content,
|
||||
: themed,
|
||||
),
|
||||
);
|
||||
// The colour bar runs the row's whole height, divider included, and
|
||||
// the tint fills the divider's inset too, so coloured rows read as
|
||||
// one band each.
|
||||
// The open row's bar, else an identity colour's own bar.
|
||||
final bar = selected
|
||||
? selectionAccent ??
|
||||
accent ??
|
||||
Theme.of(context).colorScheme.primary
|
||||
var bar = selected
|
||||
? selectionAccent ?? accent ?? theme.colorScheme.primary
|
||||
: showAccentBorder
|
||||
? accent
|
||||
: null;
|
||||
// On the inverted fill the bar keeps a 3:1 contrast with it.
|
||||
if (inverted && bar != null) {
|
||||
bar = colorWithContrast(bar, theme.scaffoldBackgroundColor, 3);
|
||||
}
|
||||
Widget marked(Widget row) => bar == null
|
||||
? row
|
||||
: DecoratedBox(
|
||||
@@ -277,7 +319,12 @@ class AppListRow extends StatelessWidget {
|
||||
position: DecorationPosition.foreground,
|
||||
decoration: BoxDecoration(
|
||||
border: BorderDirectional(
|
||||
start: BorderSide(color: bar, width: kAppListRowBarWidth),
|
||||
start: BorderSide(
|
||||
color: bar,
|
||||
width: inverted
|
||||
? invertedBarWidth
|
||||
: kAppListRowBarWidth,
|
||||
),
|
||||
top: framed ? BorderSide(color: bar) : BorderSide.none,
|
||||
end: framed ? BorderSide(color: bar) : BorderSide.none,
|
||||
bottom: framed ? BorderSide(color: bar) : BorderSide.none,
|
||||
@@ -479,12 +526,11 @@ class _RowStyles {
|
||||
const _RowStyles(this.title, this.subtitle, this.time, this.divider);
|
||||
|
||||
factory _RowStyles.of(
|
||||
BuildContext context, {
|
||||
ThemeData theme, {
|
||||
required bool selected,
|
||||
required bool emphasized,
|
||||
}) {
|
||||
final weight = emphasized ? FontWeight.w700 : FontWeight.w600;
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final text = theme.textTheme;
|
||||
final muted = scheme.onSurfaceVariant;
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'compact_theme.dart';
|
||||
import 'glass_theme.dart';
|
||||
import 'high_contrast_theme.dart';
|
||||
import 'notebook_theme.dart';
|
||||
import 'paper_theme.dart';
|
||||
import 'terminal_theme.dart';
|
||||
@@ -70,6 +71,14 @@ enum AppDesign {
|
||||
'Numbered In/Out cells, like Jupyter; tidy for tool-heavy work.',
|
||||
),
|
||||
|
||||
/// An accessible look: pure black or white, larger type, 2px borders,
|
||||
/// 48px targets and a thick focus ring; readable in sunlight.
|
||||
highContrast(
|
||||
'high-contrast',
|
||||
'High contrast',
|
||||
'Pure black and white, large type, thick borders and big targets.',
|
||||
),
|
||||
|
||||
/// Translucent frosted panes over a soft gradient: rounded cards, light
|
||||
/// glass edges and gentle depth.
|
||||
glass(
|
||||
@@ -121,16 +130,19 @@ enum AppDesign {
|
||||
|
||||
/// Builds the design's theme for [brightness] from scratch, uncached;
|
||||
/// [light] and [dark] keep the result.
|
||||
ThemeData build(Brightness brightness, {String? fontFamily}) =>
|
||||
switch ((this, brightness)) {
|
||||
(standard, Brightness.light) => appLightTheme(fontFamily: fontFamily),
|
||||
(standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily),
|
||||
(terminal, _) => terminalTheme(brightness),
|
||||
(paper, _) => paperTheme(brightness, fontFamily: fontFamily),
|
||||
(compact, _) => compactTheme(brightness, fontFamily: fontFamily),
|
||||
(notebook, _) => notebookTheme(brightness, fontFamily: fontFamily),
|
||||
(glass, _) => glassTheme(brightness, fontFamily: fontFamily),
|
||||
};
|
||||
ThemeData build(Brightness brightness, {String? fontFamily}) => switch ((
|
||||
this,
|
||||
brightness,
|
||||
)) {
|
||||
(standard, Brightness.light) => appLightTheme(fontFamily: fontFamily),
|
||||
(standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily),
|
||||
(terminal, _) => terminalTheme(brightness),
|
||||
(paper, _) => paperTheme(brightness, fontFamily: fontFamily),
|
||||
(compact, _) => compactTheme(brightness, fontFamily: fontFamily),
|
||||
(notebook, _) => notebookTheme(brightness, fontFamily: fontFamily),
|
||||
(highContrast, _) => highContrastTheme(brightness, fontFamily: fontFamily),
|
||||
(glass, _) => glassTheme(brightness, fontFamily: fontFamily),
|
||||
};
|
||||
|
||||
/// Whether this design packs the interface densely
|
||||
/// ([DesignDensity.dense]); its theme hosts switch to and from it without
|
||||
@@ -195,6 +207,18 @@ enum AppDesign {
|
||||
Color(0xFF1F2124),
|
||||
Color(0xFF1F5FBF),
|
||||
),
|
||||
highContrast =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
Color(0xFF000000),
|
||||
Color(0xFFFFFFFF),
|
||||
Color(0xFFFFD60A),
|
||||
)
|
||||
: const DesignSwatch(
|
||||
Color(0xFFFFFFFF),
|
||||
Color(0xFF000000),
|
||||
Color(0xFF0040A0),
|
||||
),
|
||||
glass =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart' show kThemeAnimationDuration;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'app_design.dart';
|
||||
import 'app_design_tokens.dart';
|
||||
|
||||
/// The device's design choice. It lives in this device's (or browser's) own
|
||||
/// preferences and is never sent to a server.
|
||||
@@ -93,10 +94,17 @@ class AppDesignController extends ChangeNotifier {
|
||||
|
||||
/// How long the theme hosts blend into the current design (their
|
||||
/// `themeAnimationDuration`): Material's blend between designs of the same
|
||||
/// density, none for a switch into or out of a dense design. A dense
|
||||
/// density, none for a switch into or out of a dense design or one that
|
||||
/// asks to snap ([AppDesignTokens.snapSwitch]). A dense
|
||||
/// design's sizes (icons, controls) have no value in a comfortable theme to
|
||||
/// blend from, so a blend would pass every icon through size zero, and in
|
||||
/// the browser (skwasm) laying out the near-zero icon glyphs could hang.
|
||||
/// A design whose switches snap: a dense one, or one whose tokens ask to
|
||||
/// ([AppDesignTokens.snapSwitch], High contrast).
|
||||
static bool _snaps(AppDesign design) =>
|
||||
design.dense ||
|
||||
(design.light().extension<AppDesignTokens>()?.snapSwitch ?? false);
|
||||
|
||||
Duration get themeAnimationDuration =>
|
||||
_snapTheme ? Duration.zero : kThemeAnimationDuration;
|
||||
bool _snapTheme = false;
|
||||
@@ -104,7 +112,7 @@ class AppDesignController extends ChangeNotifier {
|
||||
/// The shown design changed from [before]: decide the hosts' blend and
|
||||
/// tell them.
|
||||
void _shown(AppDesign before) {
|
||||
_snapTheme = before.dense || design.dense;
|
||||
_snapTheme = _snaps(before) || _snaps(design);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ enum TranscriptStyle {
|
||||
/// and injected prompts as italic editorial notes (Paper).
|
||||
manuscript,
|
||||
|
||||
/// Bordered blocks for the eye that needs them: the operator's turns as
|
||||
/// boxes with a thick bar in the chat's colour under a "You" label,
|
||||
/// answers as plain text on the page and activity as bordered rows that
|
||||
/// name each tool's status in words (High contrast).
|
||||
boxed,
|
||||
|
||||
/// A notebook: each operator prompt an "In [n]:" input cell and each
|
||||
/// answer its "Out [n]:" cell, numbered per turn in a fixed-width gutter,
|
||||
/// with tool calls as collapsible sub-cells (Notebook).
|
||||
@@ -57,6 +63,39 @@ enum SelectedRowStyle {
|
||||
/// A brighter glass slab inset in the list, in the design's corners, with
|
||||
/// a soft glow ring in the accent instead of a leading bar (Glass).
|
||||
glow,
|
||||
|
||||
/// The row inverted: the ink as its fill and the page as its text, with a
|
||||
/// thick bar (High contrast).
|
||||
inverted,
|
||||
}
|
||||
|
||||
/// The ring a design draws around the control with keyboard focus: [width]
|
||||
/// thick, [offset] outside the control's bounds, in [color], with a [halo]
|
||||
/// of the page between, so it reads over any fill.
|
||||
@immutable
|
||||
class FocusRingStyle {
|
||||
const FocusRingStyle({
|
||||
required this.color,
|
||||
required this.halo,
|
||||
this.width = 3,
|
||||
this.offset = 2,
|
||||
});
|
||||
|
||||
final Color color;
|
||||
final Color halo;
|
||||
final double width;
|
||||
final double offset;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is FocusRingStyle &&
|
||||
other.color == color &&
|
||||
other.halo == halo &&
|
||||
other.width == width &&
|
||||
other.offset == offset;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(color, halo, width, offset);
|
||||
}
|
||||
|
||||
/// The typography of reading text: chat messages, markdown answers and
|
||||
|
||||
@@ -68,6 +68,13 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
this.selectedRow = SelectedRowStyle.tonal,
|
||||
this.reading = const ReadingType(),
|
||||
this.chatColorSaturation = 1,
|
||||
this.stroke = 1,
|
||||
this.ringStroke = 2,
|
||||
this.focusRing,
|
||||
this.largeTargets = false,
|
||||
this.minContrast,
|
||||
this.windowRadius,
|
||||
this.snapSwitch = false,
|
||||
this.glass,
|
||||
this.density = DesignDensity.comfortable,
|
||||
});
|
||||
@@ -116,6 +123,37 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// palette as is, lower to quieten it towards ink.
|
||||
final double chatColorSaturation;
|
||||
|
||||
/// The width of the design's frames: [frameSide], flat panels, the
|
||||
/// composer pill and the floating bar pieces (High contrast's 2px).
|
||||
final double stroke;
|
||||
|
||||
/// The width of the usage ring around the composer's send button.
|
||||
final double ringStroke;
|
||||
|
||||
/// A ring the design draws around whatever has keyboard focus, over every
|
||||
/// control's own focus overlay; null leaves focus to each control.
|
||||
final FocusRingStyle? focusRing;
|
||||
|
||||
/// Whether controls keep touch-sized (48px) targets on a desktop too,
|
||||
/// rather than the pointer's compact ones.
|
||||
final bool largeTargets;
|
||||
|
||||
/// The least contrast a design's marks keep against the page: chat
|
||||
/// colours are darkened or lightened until they reach it, a chat's colour
|
||||
/// marks with bars and outlines rather than translucent tints, and faint
|
||||
/// tracks (the usage ring's) are drawn solid. Null keeps the palette and
|
||||
/// its tints.
|
||||
final double? minContrast;
|
||||
|
||||
/// The corner radius of floating windows; null keeps the windows' own.
|
||||
final double? windowRadius;
|
||||
|
||||
/// Whether a live switch into or out of this design snaps rather than
|
||||
/// blending: High contrast's half-blended frames would be low-contrast
|
||||
/// grey on grey, and its larger component sizes have no value in other
|
||||
/// designs to blend from ([AppDesignController.themeAnimationDuration]).
|
||||
final bool snapSwitch;
|
||||
|
||||
/// A glass design's translucent surfaces: the backdrop behind the app, the
|
||||
/// panes' and bars' tints, the inset cards' fill and edge, and how its
|
||||
/// corners grow. Null for an opaque design (every surface keeps its fill).
|
||||
@@ -132,6 +170,19 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
static AppDesignTokens of(BuildContext context) =>
|
||||
Theme.of(context).extension<AppDesignTokens>() ?? standard;
|
||||
|
||||
/// The same design's theme in the opposite brightness, in [theme]'s
|
||||
/// interface font: what an inverted surface (High contrast's open row)
|
||||
/// draws its content under. Cached per theme.
|
||||
static ThemeData inverseTheme(ThemeData theme) => _inverse[theme] ??= () {
|
||||
final design = (theme.extension<AppDesignTokens>() ?? standard).design;
|
||||
final family = theme.textTheme.bodyMedium?.fontFamily;
|
||||
return theme.brightness == Brightness.dark
|
||||
? design.light(fontFamily: family)
|
||||
: design.dark(fontFamily: family);
|
||||
}();
|
||||
|
||||
static final Expando<ThemeData> _inverse = Expando('inverse theme');
|
||||
|
||||
/// [designed] as this design draws it: the widget's own shape, or a
|
||||
/// rectangle with [radius] corners.
|
||||
/// A glass design keeps the widget's shape with its corners grown
|
||||
@@ -181,7 +232,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// The hairline a flat design frames its panels with; null keeps none.
|
||||
BorderSide? get frameSide {
|
||||
final color = frame;
|
||||
return color == null ? null : BorderSide(color: color);
|
||||
return color == null ? null : BorderSide(color: color, width: stroke);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -198,6 +249,13 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
SelectedRowStyle? selectedRow,
|
||||
ReadingType? reading,
|
||||
double? chatColorSaturation,
|
||||
double? stroke,
|
||||
double? ringStroke,
|
||||
FocusRingStyle? focusRing,
|
||||
bool? largeTargets,
|
||||
double? minContrast,
|
||||
double? windowRadius,
|
||||
bool? snapSwitch,
|
||||
GlassStyle? glass,
|
||||
DesignDensity? density,
|
||||
}) => AppDesignTokens(
|
||||
@@ -213,6 +271,13 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
selectedRow: selectedRow ?? this.selectedRow,
|
||||
reading: reading ?? this.reading,
|
||||
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
|
||||
stroke: stroke ?? this.stroke,
|
||||
ringStroke: ringStroke ?? this.ringStroke,
|
||||
focusRing: focusRing ?? this.focusRing,
|
||||
largeTargets: largeTargets ?? this.largeTargets,
|
||||
minContrast: minContrast ?? this.minContrast,
|
||||
windowRadius: windowRadius ?? this.windowRadius,
|
||||
snapSwitch: snapSwitch ?? this.snapSwitch,
|
||||
glass: glass ?? this.glass,
|
||||
density: density ?? this.density,
|
||||
);
|
||||
@@ -235,11 +300,18 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
other.selectedRow == selectedRow &&
|
||||
other.reading == reading &&
|
||||
other.chatColorSaturation == chatColorSaturation &&
|
||||
other.stroke == stroke &&
|
||||
other.ringStroke == ringStroke &&
|
||||
other.focusRing == focusRing &&
|
||||
other.largeTargets == largeTargets &&
|
||||
other.minContrast == minContrast &&
|
||||
other.windowRadius == windowRadius &&
|
||||
other.snapSwitch == snapSwitch &&
|
||||
other.glass == glass &&
|
||||
other.density == density;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
int get hashCode => Object.hashAll([
|
||||
design,
|
||||
radius,
|
||||
flat,
|
||||
@@ -252,9 +324,16 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
selectedRow,
|
||||
reading,
|
||||
chatColorSaturation,
|
||||
stroke,
|
||||
ringStroke,
|
||||
focusRing,
|
||||
largeTargets,
|
||||
minContrast,
|
||||
windowRadius,
|
||||
snapSwitch,
|
||||
glass,
|
||||
density,
|
||||
);
|
||||
]);
|
||||
|
||||
/// Designs switch whole: a theme animation snaps halfway rather than
|
||||
/// blending two designs' shapes.
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
|
||||
/// Draws the design's [FocusRingStyle] around whatever has keyboard focus,
|
||||
/// over the whole app (dialogs and menus included), as a browser draws its
|
||||
/// focus outline: every focusable gets the ring without per-widget code.
|
||||
///
|
||||
/// Like a browser's `:focus-visible`, it shows only while the keyboard
|
||||
/// drives: a key press turns it on and any pointer press (a click, a tap)
|
||||
/// turns it off, so clicking into the transcript draws no frame round it.
|
||||
/// It shows only under a design with a ring; otherwise it paints nothing. The overlay is always in the tree, so a design switch keeps the
|
||||
/// app's subtree. It follows a focused control as it scrolls by checking its
|
||||
/// rect after each frame the app draws anyway; it never schedules frames.
|
||||
class DesignFocusRing extends StatefulWidget {
|
||||
const DesignFocusRing({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<DesignFocusRing> createState() => _DesignFocusRingState();
|
||||
}
|
||||
|
||||
class _DesignFocusRingState extends State<DesignFocusRing> {
|
||||
final _rect = ValueNotifier<Rect?>(null);
|
||||
final _overlay = GlobalKey();
|
||||
FocusRingStyle? _style;
|
||||
bool _tracking = false;
|
||||
|
||||
/// Whether the keyboard, not a pointer, was used last.
|
||||
bool _keyboard = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
FocusManager.instance.addListener(_update);
|
||||
HardwareKeyboard.instance.addHandler(_onKey);
|
||||
GestureBinding.instance.pointerRouter.addGlobalRoute(_onPointer);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
FocusManager.instance.removeListener(_update);
|
||||
HardwareKeyboard.instance.removeHandler(_onKey);
|
||||
GestureBinding.instance.pointerRouter.removeGlobalRoute(_onPointer);
|
||||
_rect.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Notes a key press; never handles the key.
|
||||
bool _onKey(KeyEvent event) {
|
||||
if (event is KeyDownEvent && !_keyboard) {
|
||||
_keyboard = true;
|
||||
_update();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void _onPointer(PointerEvent event) {
|
||||
if (event is PointerDownEvent && _keyboard) {
|
||||
_keyboard = false;
|
||||
_update();
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the focused control is, in the overlay's coordinates; null when
|
||||
/// no ring shows.
|
||||
Rect? _measure() {
|
||||
if (_style == null || !_keyboard) return null;
|
||||
final node = FocusManager.instance.primaryFocus;
|
||||
final context = node?.context;
|
||||
if (node == null || context == null || !context.mounted) return null;
|
||||
// A scope (a route, the app) holds focus between controls: no ring.
|
||||
if (node is FocusScopeNode) return null;
|
||||
// A text field's ring goes round its whole decorated field, not the
|
||||
// text inside it.
|
||||
RenderObject? box = context.findRenderObject();
|
||||
var steps = 0;
|
||||
context.visitAncestorElements((element) {
|
||||
if (element.widget is InputDecorator) {
|
||||
box = element.findRenderObject();
|
||||
return false;
|
||||
}
|
||||
return ++steps < 40;
|
||||
});
|
||||
final overlay = _overlay.currentContext?.findRenderObject();
|
||||
final target = box;
|
||||
if (target is! RenderBox || !target.hasSize || !target.attached) {
|
||||
return null;
|
||||
}
|
||||
if (overlay is! RenderBox || !overlay.hasSize) return null;
|
||||
final rect = MatrixUtils.transformRect(
|
||||
target.getTransformTo(overlay),
|
||||
Offset.zero & target.size,
|
||||
);
|
||||
if (rect.isEmpty || !(Offset.zero & overlay.size).overlaps(rect)) {
|
||||
return null;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
void _update() {
|
||||
if (!mounted) return;
|
||||
_rect.value = _measure();
|
||||
// While a ring shows, check its rect after each frame (a scroll, a
|
||||
// layout change); a post-frame callback alone schedules no frame.
|
||||
if (_rect.value != null && !_tracking) {
|
||||
_tracking = true;
|
||||
SchedulerBinding.instance.addPostFrameCallback(_afterFrame);
|
||||
}
|
||||
}
|
||||
|
||||
void _afterFrame(Duration _) {
|
||||
_tracking = false;
|
||||
_update();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = AppDesignTokens.of(context).focusRing;
|
||||
if (style != _style) {
|
||||
_style = style;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _update());
|
||||
}
|
||||
return Stack(
|
||||
fit: StackFit.passthrough,
|
||||
children: [
|
||||
widget.child,
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: RepaintBoundary(
|
||||
child: CustomPaint(
|
||||
key: _overlay,
|
||||
painter: style == null
|
||||
? null
|
||||
: FocusRingPainter(
|
||||
rect: _rect,
|
||||
style: style,
|
||||
radius: AppDesignTokens.of(context).radius ?? 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Paints [style]'s ring around [rect]: a halo of the page colour, then the
|
||||
/// ring, [FocusRingStyle.offset] outside the control, with rounded corners.
|
||||
class FocusRingPainter extends CustomPainter {
|
||||
FocusRingPainter({
|
||||
required this.rect,
|
||||
required this.style,
|
||||
required this.radius,
|
||||
}) : super(repaint: rect);
|
||||
|
||||
final ValueListenable<Rect?> rect;
|
||||
final FocusRingStyle style;
|
||||
|
||||
/// The control's corner radius; the ring's corners keep it concentric.
|
||||
final double radius;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final target = rect.value;
|
||||
if (target == null) return;
|
||||
final ring = target.inflate(style.offset + style.width / 2);
|
||||
final corner = Radius.circular(radius + style.offset);
|
||||
canvas
|
||||
..drawRRect(
|
||||
RRect.fromRectAndRadius(target.inflate(style.offset / 2), corner),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = style.offset
|
||||
..color = style.halo,
|
||||
)
|
||||
..drawRRect(
|
||||
RRect.fromRectAndRadius(ring, corner),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = style.width
|
||||
..color = style.color,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(FocusRingPainter old) =>
|
||||
old.rect != rect || old.style != style || old.radius != radius;
|
||||
}
|
||||
@@ -83,6 +83,10 @@ ThemeData glassTheme(Brightness brightness, {String? fontFamily}) {
|
||||
selectedRow: SelectedRowStyle.glow,
|
||||
reading: glassReading,
|
||||
glass: style,
|
||||
// A live switch snaps: a blend half-way between clear glass pages
|
||||
// and an opaque design re-rasterises the whole translucent stack
|
||||
// every frame, and in the browser (skwasm) it could stall.
|
||||
snapSwitch: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,345 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'high_contrast_palette.dart';
|
||||
import 'high_contrast_theme.dart';
|
||||
|
||||
const Color _clear = Color(0x00000000);
|
||||
|
||||
/// The state resolvers High contrast's controls use, built once per
|
||||
/// brightness: a resolver compares by identity, so fresh ones would make a
|
||||
/// rebuilt theme unequal to the last (test/perf/design_bench_test.dart).
|
||||
class _Resolvers {
|
||||
_Resolvers(ColorScheme scheme)
|
||||
: disabled = highContrastDisabled(scheme.brightness) {
|
||||
final ink = scheme.onSurface;
|
||||
BorderSide side(Color color) =>
|
||||
BorderSide(color: color, width: highContrastStroke);
|
||||
outline = WidgetStateProperty.resolveWith(
|
||||
(states) => side(states.contains(WidgetState.disabled) ? disabled : ink),
|
||||
);
|
||||
filledSide = WidgetStateProperty.resolveWith(
|
||||
(states) => side(
|
||||
states.contains(WidgetState.disabled) ? disabled : scheme.primary,
|
||||
),
|
||||
);
|
||||
filledBackground = WidgetStateProperty.resolveWith(
|
||||
(states) =>
|
||||
states.contains(WidgetState.disabled) ? _clear : scheme.primary,
|
||||
);
|
||||
filledForeground = _foreground(scheme.onPrimary);
|
||||
primaryForeground = _foreground(scheme.primary);
|
||||
inkForeground = _foreground(ink);
|
||||
chipSide = WidgetStateBorderSide.resolveWith(
|
||||
(states) => side(states.contains(WidgetState.disabled) ? disabled : ink),
|
||||
);
|
||||
segmentBackground = WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.selected)
|
||||
? scheme.secondaryContainer
|
||||
: _clear,
|
||||
);
|
||||
segmentForeground = WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled)
|
||||
? disabled
|
||||
: states.contains(WidgetState.selected)
|
||||
? scheme.onSecondaryContainer
|
||||
: ink,
|
||||
);
|
||||
checkboxSide = WidgetStateBorderSide.resolveWith(
|
||||
(states) => side(
|
||||
states.contains(WidgetState.disabled)
|
||||
? disabled
|
||||
: states.contains(WidgetState.selected)
|
||||
? scheme.primary
|
||||
: ink,
|
||||
),
|
||||
);
|
||||
trackOutline = WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled)
|
||||
? disabled
|
||||
: states.contains(WidgetState.selected)
|
||||
? scheme.primary
|
||||
: ink,
|
||||
);
|
||||
selectedInk = WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled)
|
||||
? disabled
|
||||
: states.contains(WidgetState.selected)
|
||||
? scheme.primary
|
||||
: ink,
|
||||
);
|
||||
// One border resolved by state (the field's own `InputBorder.none`
|
||||
// replaces it whole): 3px of the accent while focused, the error red,
|
||||
// the disabled ink, else 2px of the ink.
|
||||
field = WidgetStateInputBorder.resolveWith((states) {
|
||||
final color = states.contains(WidgetState.disabled)
|
||||
? disabled
|
||||
: states.contains(WidgetState.error)
|
||||
? scheme.error
|
||||
: states.contains(WidgetState.focused)
|
||||
? scheme.primary
|
||||
: ink;
|
||||
return OutlineInputBorder(
|
||||
borderRadius: HighContrastSurfaces.corners,
|
||||
borderSide: BorderSide(
|
||||
color: color,
|
||||
width: states.contains(WidgetState.focused)
|
||||
? highContrastFocusWidth
|
||||
: highContrastStroke,
|
||||
),
|
||||
);
|
||||
});
|
||||
overlay = WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return ink.withValues(alpha: 0.2);
|
||||
}
|
||||
if (states.contains(WidgetState.focused)) {
|
||||
return scheme.primary.withValues(alpha: 0.24);
|
||||
}
|
||||
if (states.contains(WidgetState.hovered)) {
|
||||
return ink.withValues(alpha: 0.12);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
final Color disabled;
|
||||
late final WidgetStateProperty<BorderSide> outline;
|
||||
late final WidgetStateProperty<BorderSide> filledSide;
|
||||
late final WidgetStateProperty<Color> filledBackground;
|
||||
late final WidgetStateProperty<Color> filledForeground;
|
||||
late final WidgetStateProperty<Color> primaryForeground;
|
||||
late final WidgetStateProperty<Color> inkForeground;
|
||||
late final WidgetStateBorderSide chipSide;
|
||||
late final WidgetStateProperty<Color> segmentBackground;
|
||||
late final WidgetStateProperty<Color> segmentForeground;
|
||||
late final WidgetStateBorderSide checkboxSide;
|
||||
late final WidgetStateProperty<Color> trackOutline;
|
||||
late final WidgetStateProperty<Color> selectedInk;
|
||||
late final WidgetStateProperty<Color?> overlay;
|
||||
late final InputBorder field;
|
||||
|
||||
/// [color], or the disabled ink (4.5:1 or more) on a disabled control.
|
||||
WidgetStateProperty<Color> _foreground(Color color) =>
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.disabled) ? disabled : color,
|
||||
);
|
||||
}
|
||||
|
||||
final Map<Brightness, _Resolvers> _resolvers = {};
|
||||
|
||||
/// [base] with High contrast's controls: every button, field, chip, menu,
|
||||
/// segmented button, checkbox, switch and slider 48px tall at least, in
|
||||
/// [highContrastRadius] corners with 2px borders, no elevation, disabled
|
||||
/// text that still reads at 4.5:1 and the selected state inverted.
|
||||
/// Text and icon buttons stay unframed (an action in a sentence or a
|
||||
/// toolbar), with 48px targets, strong hover and the focus ring.
|
||||
///
|
||||
/// Button text keeps the theme's own `labelLarge` (16px, weight 600): a
|
||||
/// button style's text style is animated when the design switches, and a
|
||||
/// style from the unlocalized text theme cannot blend with the default.
|
||||
ThemeData highContrastControls(ThemeData base, HighContrastSurfaces surfaces) {
|
||||
final scheme = base.colorScheme;
|
||||
final r = _resolvers[scheme.brightness] ??= _Resolvers(scheme);
|
||||
final text = base.textTheme;
|
||||
const rounded = HighContrastSurfaces.rounded;
|
||||
const minimum = WidgetStatePropertyAll(Size(48, 48));
|
||||
ButtonStyle buttons(ButtonStyle? style) =>
|
||||
(style ?? const ButtonStyle()).copyWith(
|
||||
shape: const WidgetStatePropertyAll(rounded),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(_clear),
|
||||
minimumSize: minimum,
|
||||
overlayColor: r.overlay,
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
),
|
||||
);
|
||||
final menu = MenuStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(scheme.surface),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(_clear),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
||||
shape: WidgetStatePropertyAll(surfaces.framed),
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 6)),
|
||||
);
|
||||
return base.copyWith(
|
||||
menuTheme: MenuThemeData(style: menu),
|
||||
dropdownMenuTheme: DropdownMenuThemeData(
|
||||
menuStyle: menu,
|
||||
textStyle: text.bodyLarge,
|
||||
),
|
||||
menuButtonTheme: MenuButtonThemeData(
|
||||
style: MenuItemButton.styleFrom(
|
||||
shape: rounded,
|
||||
minimumSize: const Size(48, 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
).copyWith(overlayColor: r.overlay),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
style: buttons(base.filledButtonTheme.style).copyWith(
|
||||
backgroundColor: r.filledBackground,
|
||||
foregroundColor: r.filledForeground,
|
||||
side: r.filledSide,
|
||||
),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: buttons(base.elevatedButtonTheme.style).copyWith(
|
||||
backgroundColor: WidgetStatePropertyAll(scheme.surface),
|
||||
foregroundColor: r.primaryForeground,
|
||||
side: r.outline,
|
||||
),
|
||||
),
|
||||
outlinedButtonTheme: OutlinedButtonThemeData(
|
||||
style: buttons(
|
||||
base.outlinedButtonTheme.style,
|
||||
).copyWith(side: r.outline, foregroundColor: r.primaryForeground),
|
||||
),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: buttons(base.textButtonTheme.style).copyWith(
|
||||
foregroundColor: r.primaryForeground,
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
),
|
||||
),
|
||||
),
|
||||
iconButtonTheme: IconButtonThemeData(
|
||||
style: (base.iconButtonTheme.style ?? const ButtonStyle()).copyWith(
|
||||
shape: const WidgetStatePropertyAll(rounded),
|
||||
minimumSize: minimum,
|
||||
overlayColor: r.overlay,
|
||||
foregroundColor: r.inkForeground,
|
||||
),
|
||||
),
|
||||
segmentedButtonTheme: SegmentedButtonThemeData(
|
||||
style: buttons(base.segmentedButtonTheme.style).copyWith(
|
||||
side: r.outline,
|
||||
backgroundColor: r.segmentBackground,
|
||||
foregroundColor: r.segmentForeground,
|
||||
iconColor: r.segmentForeground,
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
elevation: 0,
|
||||
focusElevation: 0,
|
||||
hoverElevation: 0,
|
||||
highlightElevation: 0,
|
||||
backgroundColor: scheme.primary,
|
||||
foregroundColor: scheme.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: HighContrastSurfaces.corners,
|
||||
side: BorderSide(color: scheme.onSurface, width: highContrastStroke),
|
||||
),
|
||||
),
|
||||
// Chosen chips inverted; every chip framed in the ink.
|
||||
chipTheme: ChipThemeData(
|
||||
backgroundColor: _clear,
|
||||
selectedColor: scheme.secondaryContainer,
|
||||
disabledColor: _clear,
|
||||
checkmarkColor: scheme.onSecondaryContainer,
|
||||
shape: rounded,
|
||||
side: r.chipSide,
|
||||
elevation: 0,
|
||||
pressElevation: 0,
|
||||
labelStyle: text.labelLarge?.copyWith(color: scheme.onSurface),
|
||||
secondaryLabelStyle: text.labelLarge?.copyWith(
|
||||
color: scheme.onSecondaryContainer,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 6),
|
||||
),
|
||||
// Only the base border: a field that sets `InputBorder.none` (the
|
||||
// composer, whose frame is its pill) keeps none in every state.
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
border: r.field,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 14),
|
||||
labelStyle: text.bodyLarge?.copyWith(color: scheme.onSurfaceVariant),
|
||||
hintStyle: text.bodyLarge?.copyWith(color: scheme.onSurfaceVariant),
|
||||
errorStyle: text.bodySmall?.copyWith(color: scheme.error),
|
||||
),
|
||||
searchBarTheme: SearchBarThemeData(
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shape: const WidgetStatePropertyAll(rounded),
|
||||
side: WidgetStatePropertyAll(surfaces.border),
|
||||
backgroundColor: WidgetStatePropertyAll(scheme.surface),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
||||
overlayColor: r.overlay,
|
||||
constraints: const BoxConstraints(minHeight: 48),
|
||||
textStyle: WidgetStatePropertyAll(text.bodyLarge),
|
||||
hintStyle: WidgetStatePropertyAll(
|
||||
text.bodyLarge?.copyWith(color: scheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
listTileTheme: ListTileThemeData(
|
||||
shape: rounded,
|
||||
minTileHeight: 48,
|
||||
selectedColor: scheme.onSecondaryContainer,
|
||||
selectedTileColor: scheme.secondaryContainer,
|
||||
),
|
||||
expansionTileTheme: ExpansionTileThemeData(
|
||||
shape: const Border(),
|
||||
collapsedShape: const Border(),
|
||||
iconColor: scheme.onSurface,
|
||||
collapsedIconColor: scheme.onSurface,
|
||||
),
|
||||
tabBarTheme: TabBarThemeData(
|
||||
dividerColor: scheme.outlineVariant,
|
||||
dividerHeight: highContrastStroke,
|
||||
labelColor: scheme.onSurface,
|
||||
unselectedLabelColor: scheme.onSurfaceVariant,
|
||||
labelStyle: text.titleSmall?.copyWith(fontWeight: FontWeight.w800),
|
||||
unselectedLabelStyle: text.titleSmall,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicator: _tabIndicators[scheme.primary] ??= UnderlineTabIndicator(
|
||||
borderSide: BorderSide(color: scheme.primary, width: 4),
|
||||
),
|
||||
overlayColor: r.overlay,
|
||||
),
|
||||
switchTheme: SwitchThemeData(
|
||||
trackOutlineColor: r.trackOutline,
|
||||
trackOutlineWidth: const WidgetStatePropertyAll(highContrastStroke),
|
||||
),
|
||||
checkboxTheme: CheckboxThemeData(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(3)),
|
||||
),
|
||||
side: r.checkboxSide,
|
||||
checkColor: WidgetStatePropertyAll(scheme.onPrimary),
|
||||
),
|
||||
radioTheme: RadioThemeData(fillColor: r.selectedInk),
|
||||
sliderTheme: SliderThemeData(
|
||||
trackHeight: 6,
|
||||
activeTrackColor: scheme.primary,
|
||||
inactiveTrackColor: scheme.outlineVariant,
|
||||
thumbColor: scheme.primary,
|
||||
overlayColor: scheme.primary.withValues(alpha: 0.24),
|
||||
valueIndicatorColor: scheme.inverseSurface,
|
||||
valueIndicatorTextStyle: text.labelLarge?.copyWith(
|
||||
color: scheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
// Counts in the accent, larger, in heavy figures.
|
||||
badgeTheme: BadgeThemeData(
|
||||
backgroundColor: scheme.primary,
|
||||
textColor: scheme.onPrimary,
|
||||
smallSize: 10,
|
||||
largeSize: 20,
|
||||
textStyle: text.labelSmall?.copyWith(fontWeight: FontWeight.w800),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
),
|
||||
progressIndicatorTheme: ProgressIndicatorThemeData(
|
||||
color: scheme.primary,
|
||||
linearTrackColor: scheme.outlineVariant,
|
||||
circularTrackColor: _clear,
|
||||
linearMinHeight: 6,
|
||||
),
|
||||
scrollbarTheme: ScrollbarThemeData(
|
||||
radius: const Radius.circular(highContrastRadius),
|
||||
thickness: const WidgetStatePropertyAll(8),
|
||||
thumbColor: WidgetStatePropertyAll(scheme.onSurfaceVariant),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final Map<Color, Decoration> _tabIndicators = {};
|
||||
@@ -0,0 +1,172 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
|
||||
/// The WCAG 2 contrast ratio of [a] against [b] (1 to 21), both opaque.
|
||||
double contrastRatio(Color a, Color b) {
|
||||
final la = a.computeLuminance();
|
||||
final lb = b.computeLuminance();
|
||||
final hi = la > lb ? la : lb;
|
||||
final lo = la > lb ? lb : la;
|
||||
return (hi + 0.05) / (lo + 0.05);
|
||||
}
|
||||
|
||||
/// WCAG AAA for body text: what High contrast's reading text and its
|
||||
/// status accents reach against the page.
|
||||
const double highContrastText = 7;
|
||||
|
||||
/// WCAG AA for everything else: secondary text, disabled text, borders and
|
||||
/// chat colours reach at least this against the page.
|
||||
const double highContrastMinimum = 4.5;
|
||||
|
||||
/// The one strong accent on the black page: a bright yellow (14.9:1).
|
||||
const Color highContrastYellow = Color(0xFFFFD60A);
|
||||
|
||||
/// The accent on the white page: a deep blue (9.4:1); yellow cannot meet
|
||||
/// contrast on white.
|
||||
const Color highContrastBlue = Color(0xFF0040A0);
|
||||
|
||||
/// The dark page's error red: bright, and still 7.6:1 against black.
|
||||
const Color highContrastDarkRed = Color(0xFFFF6B6B);
|
||||
|
||||
/// The light page's error red (7.4:1 against white).
|
||||
const Color highContrastLightRed = Color(0xFFB00000);
|
||||
|
||||
/// Disabled text and borders: plainly greyer than the ink, and still 4.5:1
|
||||
/// or more against the page (6.5:1 on black, 5.1:1 on white).
|
||||
const Color highContrastDarkDisabled = Color(0xFF8F8F8F);
|
||||
const Color highContrastLightDisabled = Color(0xFF6E6E6E);
|
||||
|
||||
/// High contrast's status accents on black: each reads at 7:1 or more, so
|
||||
/// a status word in its colour is body-text legible.
|
||||
const AnsiAccents highContrastDarkAccents = AnsiAccents(
|
||||
green: Color(0xFF3DFF6E),
|
||||
cyan: Color(0xFF00E5FF),
|
||||
yellow: highContrastYellow,
|
||||
red: highContrastDarkRed,
|
||||
magenta: Color(0xFFFF80FF),
|
||||
blue: Color(0xFF6CB4FF),
|
||||
);
|
||||
|
||||
/// High contrast's status accents on white, each 7:1 or more.
|
||||
const AnsiAccents highContrastLightAccents = AnsiAccents(
|
||||
green: Color(0xFF006400),
|
||||
cyan: Color(0xFF005F6B),
|
||||
yellow: Color(0xFF6B5000),
|
||||
red: highContrastLightRed,
|
||||
magenta: Color(0xFF8B008B),
|
||||
blue: highContrastBlue,
|
||||
);
|
||||
|
||||
/// High contrast's colour scheme: a pure black page with white ink and a
|
||||
/// yellow accent (dark), or a pure white page with black ink and a deep blue
|
||||
/// accent (light). Every surface container is the page itself: panels part
|
||||
/// by their borders ([ColorScheme.outline], the ink), not by tone. The
|
||||
/// secondary container is the ink, so a selected thing (a navigation
|
||||
/// indicator, a chosen chip, the open row) reads inverted.
|
||||
ColorScheme highContrastColorScheme(Brightness brightness) {
|
||||
if (brightness == Brightness.dark) {
|
||||
return const ColorScheme(
|
||||
brightness: Brightness.dark,
|
||||
primary: highContrastYellow,
|
||||
onPrimary: Color(0xFF000000),
|
||||
primaryContainer: highContrastYellow,
|
||||
onPrimaryContainer: Color(0xFF000000),
|
||||
secondary: Color(0xFFFFFFFF),
|
||||
onSecondary: Color(0xFF000000),
|
||||
secondaryContainer: Color(0xFFFFFFFF),
|
||||
onSecondaryContainer: Color(0xFF000000),
|
||||
tertiary: Color(0xFFFF9F0A),
|
||||
onTertiary: Color(0xFF000000),
|
||||
tertiaryContainer: Color(0xFFFF9F0A),
|
||||
onTertiaryContainer: Color(0xFF000000),
|
||||
error: highContrastDarkRed,
|
||||
onError: Color(0xFF000000),
|
||||
errorContainer: Color(0xFF000000),
|
||||
onErrorContainer: highContrastDarkRed,
|
||||
surface: Color(0xFF000000),
|
||||
onSurface: Color(0xFFFFFFFF),
|
||||
onSurfaceVariant: Color(0xFFD0D0D0),
|
||||
surfaceDim: Color(0xFF000000),
|
||||
surfaceBright: Color(0xFF000000),
|
||||
surfaceContainerLowest: Color(0xFF000000),
|
||||
surfaceContainerLow: Color(0xFF000000),
|
||||
surfaceContainer: Color(0xFF000000),
|
||||
surfaceContainerHigh: Color(0xFF000000),
|
||||
surfaceContainerHighest: Color(0xFF000000),
|
||||
outline: Color(0xFFFFFFFF),
|
||||
outlineVariant: Color(0xFF9E9E9E),
|
||||
shadow: Color(0x00000000),
|
||||
scrim: Color(0xFF000000),
|
||||
inverseSurface: Color(0xFFFFFFFF),
|
||||
onInverseSurface: Color(0xFF000000),
|
||||
inversePrimary: highContrastBlue,
|
||||
surfaceTint: Color(0x00000000),
|
||||
);
|
||||
}
|
||||
return const ColorScheme(
|
||||
brightness: Brightness.light,
|
||||
primary: highContrastBlue,
|
||||
onPrimary: Color(0xFFFFFFFF),
|
||||
primaryContainer: highContrastBlue,
|
||||
onPrimaryContainer: Color(0xFFFFFFFF),
|
||||
secondary: Color(0xFF000000),
|
||||
onSecondary: Color(0xFFFFFFFF),
|
||||
secondaryContainer: Color(0xFF000000),
|
||||
onSecondaryContainer: Color(0xFFFFFFFF),
|
||||
tertiary: Color(0xFF8A3B00),
|
||||
onTertiary: Color(0xFFFFFFFF),
|
||||
tertiaryContainer: Color(0xFF8A3B00),
|
||||
onTertiaryContainer: Color(0xFFFFFFFF),
|
||||
error: highContrastLightRed,
|
||||
onError: Color(0xFFFFFFFF),
|
||||
errorContainer: Color(0xFFFFFFFF),
|
||||
onErrorContainer: highContrastLightRed,
|
||||
surface: Color(0xFFFFFFFF),
|
||||
onSurface: Color(0xFF000000),
|
||||
onSurfaceVariant: Color(0xFF333333),
|
||||
surfaceDim: Color(0xFFFFFFFF),
|
||||
surfaceBright: Color(0xFFFFFFFF),
|
||||
surfaceContainerLowest: Color(0xFFFFFFFF),
|
||||
surfaceContainerLow: Color(0xFFFFFFFF),
|
||||
surfaceContainer: Color(0xFFFFFFFF),
|
||||
surfaceContainerHigh: Color(0xFFFFFFFF),
|
||||
surfaceContainerHighest: Color(0xFFFFFFFF),
|
||||
outline: Color(0xFF000000),
|
||||
outlineVariant: Color(0xFF595959),
|
||||
shadow: Color(0x00000000),
|
||||
scrim: Color(0xFF000000),
|
||||
inverseSurface: Color(0xFF000000),
|
||||
onInverseSurface: Color(0xFFFFFFFF),
|
||||
inversePrimary: highContrastYellow,
|
||||
surfaceTint: Color(0x00000000),
|
||||
);
|
||||
}
|
||||
|
||||
/// The disabled ink for [brightness] ([highContrastDarkDisabled] or
|
||||
/// [highContrastLightDisabled]).
|
||||
Color highContrastDisabled(Brightness brightness) =>
|
||||
brightness == Brightness.dark
|
||||
? highContrastDarkDisabled
|
||||
: highContrastLightDisabled;
|
||||
|
||||
/// [color] with its lightness moved away from [page] in small steps until
|
||||
/// it reaches [ratio] against it, keeping its hue and saturation. Cached:
|
||||
/// a design has a handful of marks and two pages.
|
||||
Color colorWithContrast(Color color, Color page, double ratio) =>
|
||||
_withContrast[(color, page, ratio)] ??= _moveToContrast(color, page, ratio);
|
||||
|
||||
final Map<(Color, Color, double), Color> _withContrast = {};
|
||||
|
||||
Color _moveToContrast(Color color, Color page, double ratio) {
|
||||
final lighter = page.computeLuminance() < 0.5;
|
||||
var hsl = HSLColor.fromColor(color);
|
||||
var result = color;
|
||||
while (contrastRatio(result, page) < ratio) {
|
||||
final next = (hsl.lightness + (lighter ? 0.02 : -0.02)).clamp(0.0, 1.0);
|
||||
if (next == hsl.lightness) break;
|
||||
hsl = hsl.withLightness(next);
|
||||
result = hsl.toColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design.dart';
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'high_contrast_controls.dart';
|
||||
import 'high_contrast_palette.dart';
|
||||
import 'high_contrast_typography.dart';
|
||||
|
||||
/// High contrast's corner radius: moderate, so a box still reads as a box
|
||||
/// at a glance in sunlight.
|
||||
const double highContrastRadius = 6;
|
||||
|
||||
/// The width of every control's and panel's border.
|
||||
const double highContrastStroke = 2;
|
||||
|
||||
/// The width of the keyboard focus ring.
|
||||
const double highContrastFocusWidth = 3;
|
||||
|
||||
/// High contrast's shapes and borders, from its scheme.
|
||||
class HighContrastSurfaces {
|
||||
HighContrastSurfaces(this.scheme);
|
||||
|
||||
final ColorScheme scheme;
|
||||
|
||||
static const BorderRadius corners = BorderRadius.all(
|
||||
Radius.circular(highContrastRadius),
|
||||
);
|
||||
|
||||
/// The border of controls and floating pieces: 2px of the ink.
|
||||
BorderSide get border =>
|
||||
BorderSide(color: scheme.outline, width: highContrastStroke);
|
||||
|
||||
/// A structural rule (app bar, tab bar): 2px of the secondary ink, so the
|
||||
/// page's structure stays quieter than its controls.
|
||||
BorderSide get rule =>
|
||||
BorderSide(color: scheme.outlineVariant, width: highContrastStroke);
|
||||
|
||||
RoundedRectangleBorder get framed =>
|
||||
RoundedRectangleBorder(borderRadius: corners, side: border);
|
||||
|
||||
static const RoundedRectangleBorder rounded = RoundedRectangleBorder(
|
||||
borderRadius: corners,
|
||||
);
|
||||
}
|
||||
|
||||
/// The High contrast design's theme: a pure black page with white ink and a
|
||||
/// yellow accent (or pure white with black ink and a deep blue accent),
|
||||
/// larger and heavier type, 2px borders on every control and panel, flat
|
||||
/// surfaces without shadows, [highContrastRadius] corners, 48px targets on
|
||||
/// every platform and a 3px keyboard focus ring ([FocusRingStyle]).
|
||||
ThemeData highContrastTheme(Brightness brightness, {String? fontFamily}) {
|
||||
final scheme = highContrastColorScheme(brightness);
|
||||
final surfaces = HighContrastSurfaces(scheme);
|
||||
final dark = brightness == Brightness.dark;
|
||||
const clear = Color(0x00000000);
|
||||
final base = ThemeData(
|
||||
platform: kIsWeb ? TargetPlatform.android : null,
|
||||
colorScheme: scheme,
|
||||
fontFamily: fontFamily,
|
||||
scaffoldBackgroundColor: scheme.surface,
|
||||
canvasColor: scheme.surface,
|
||||
pageTransitionsTheme: appPageTransitions,
|
||||
// Touch-sized targets on a desktop too.
|
||||
visualDensity: VisualDensity.standard,
|
||||
materialTapTargetSize: MaterialTapTargetSize.padded,
|
||||
dividerColor: scheme.outlineVariant,
|
||||
disabledColor: highContrastDisabled(brightness),
|
||||
hintColor: scheme.onSurfaceVariant,
|
||||
shadowColor: clear,
|
||||
hoverColor: scheme.onSurface.withValues(alpha: 0.12),
|
||||
focusColor: scheme.primary.withValues(alpha: 0.24),
|
||||
extensions: [
|
||||
AppDesignTokens(
|
||||
design: AppDesign.highContrast,
|
||||
radius: highContrastRadius,
|
||||
flat: true,
|
||||
frame: scheme.outline,
|
||||
panel: scheme.surface,
|
||||
ansi: dark ? highContrastDarkAccents : highContrastLightAccents,
|
||||
transcript: TranscriptStyle.boxed,
|
||||
selectedRow: SelectedRowStyle.inverted,
|
||||
stroke: highContrastStroke,
|
||||
ringStroke: 3,
|
||||
focusRing: FocusRingStyle(
|
||||
color: scheme.primary,
|
||||
halo: scheme.surface,
|
||||
width: highContrastFocusWidth,
|
||||
),
|
||||
largeTargets: true,
|
||||
minContrast: highContrastMinimum,
|
||||
windowRadius: highContrastRadius,
|
||||
snapSwitch: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
final text = highContrastTextTheme(base.textTheme);
|
||||
final framed = surfaces.framed;
|
||||
return highContrastControls(
|
||||
base.copyWith(
|
||||
textTheme: text,
|
||||
primaryTextTheme: highContrastTextTheme(base.primaryTextTheme),
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: scheme.surface,
|
||||
foregroundColor: scheme.onSurface,
|
||||
surfaceTintColor: clear,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
shape: Border(bottom: surfaces.rule),
|
||||
titleTextStyle: text.titleLarge?.copyWith(color: scheme.onSurface),
|
||||
),
|
||||
cardTheme: CardThemeData(
|
||||
elevation: 0,
|
||||
shadowColor: clear,
|
||||
surfaceTintColor: clear,
|
||||
shape: framed,
|
||||
),
|
||||
dialogTheme: DialogThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
surfaceTintColor: clear,
|
||||
elevation: 0,
|
||||
shape: framed,
|
||||
),
|
||||
bottomSheetTheme: BottomSheetThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
modalBackgroundColor: scheme.surface,
|
||||
surfaceTintColor: clear,
|
||||
elevation: 0,
|
||||
modalElevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(highContrastRadius),
|
||||
),
|
||||
side: surfaces.border,
|
||||
),
|
||||
dragHandleColor: scheme.onSurface,
|
||||
),
|
||||
popupMenuTheme: PopupMenuThemeData(
|
||||
color: scheme.surface,
|
||||
surfaceTintColor: clear,
|
||||
elevation: 0,
|
||||
shape: framed,
|
||||
),
|
||||
// The ink's own colour inverted, framed, so a snack bar stands apart
|
||||
// from the page without a shadow.
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
backgroundColor: scheme.inverseSurface,
|
||||
contentTextStyle: text.bodyLarge?.copyWith(
|
||||
color: scheme.onInverseSurface,
|
||||
),
|
||||
actionTextColor: scheme.inversePrimary,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: HighContrastSurfaces.corners,
|
||||
side: BorderSide(
|
||||
color: scheme.onInverseSurface,
|
||||
width: highContrastStroke,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Tooltips large and inverted, inside a border in the page colour so
|
||||
// one over an inverted row still has an edge.
|
||||
tooltipTheme: TooltipThemeData(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.inverseSurface,
|
||||
borderRadius: HighContrastSurfaces.corners,
|
||||
border: Border.all(color: scheme.surface, width: highContrastStroke),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
textStyle: text.bodyMedium?.copyWith(
|
||||
color: scheme.onInverseSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
dividerTheme: DividerThemeData(
|
||||
color: scheme.outlineVariant,
|
||||
thickness: 1,
|
||||
space: 1,
|
||||
),
|
||||
navigationRailTheme: NavigationRailThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
elevation: 0,
|
||||
indicatorColor: scheme.secondaryContainer,
|
||||
indicatorShape: HighContrastSurfaces.rounded,
|
||||
selectedIconTheme: IconThemeData(color: scheme.onSecondaryContainer),
|
||||
unselectedIconTheme: IconThemeData(color: scheme.onSurface),
|
||||
selectedLabelTextStyle: text.labelMedium?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
unselectedLabelTextStyle: text.labelMedium?.copyWith(
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
elevation: 0,
|
||||
indicatorColor: scheme.secondaryContainer,
|
||||
indicatorShape: HighContrastSurfaces.rounded,
|
||||
surfaceTintColor: clear,
|
||||
),
|
||||
drawerTheme: DrawerThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
surfaceTintColor: clear,
|
||||
elevation: 0,
|
||||
shape: Border(right: surfaces.border),
|
||||
),
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: scheme.primary,
|
||||
selectionColor: scheme.primary.withValues(alpha: dark ? 0.45 : 0.3),
|
||||
selectionHandleColor: scheme.primary,
|
||||
),
|
||||
),
|
||||
surfaces,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// [base] at High contrast's larger, heavier sizes: body text at 17/16/14px
|
||||
/// in weight 500, labels at 16/14/13px and titles in weight 600, so thin
|
||||
/// strokes never wash out in sunlight. Sizes stay theme roles, so the
|
||||
/// operator's text scaling and the system's bold-text setting (which
|
||||
/// [Text] applies over these weights) still apply.
|
||||
TextTheme highContrastTextTheme(TextTheme base) {
|
||||
TextStyle? set(TextStyle? style, double size, FontWeight weight) =>
|
||||
style?.copyWith(fontSize: size, fontWeight: weight, letterSpacing: 0.1);
|
||||
TextStyle? heavier(TextStyle? style) =>
|
||||
style?.copyWith(fontWeight: FontWeight.w600);
|
||||
return base.copyWith(
|
||||
displayLarge: heavier(base.displayLarge),
|
||||
displayMedium: heavier(base.displayMedium),
|
||||
displaySmall: heavier(base.displaySmall),
|
||||
headlineLarge: heavier(base.headlineLarge),
|
||||
headlineMedium: heavier(base.headlineMedium),
|
||||
headlineSmall: heavier(base.headlineSmall),
|
||||
titleLarge: set(base.titleLarge, 22, FontWeight.w600),
|
||||
titleMedium: set(base.titleMedium, 18, FontWeight.w600),
|
||||
titleSmall: set(base.titleSmall, 16, FontWeight.w600),
|
||||
bodyLarge: set(base.bodyLarge, 17, FontWeight.w500),
|
||||
bodyMedium: set(base.bodyMedium, 16, FontWeight.w500),
|
||||
bodySmall: set(base.bodySmall, 14, FontWeight.w500),
|
||||
labelLarge: set(base.labelLarge, 16, FontWeight.w600),
|
||||
labelMedium: set(base.labelMedium, 14, FontWeight.w600),
|
||||
labelSmall: set(base.labelSmall, 13, FontWeight.w600),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
# High contrast design
|
||||
|
||||
An accessibility design (Settings > Design > High contrast, id
|
||||
`high-contrast`) for low vision and phones in sunlight: a pure black page with
|
||||
white ink and one bright yellow accent (dark), or a pure white page with black
|
||||
ink and a deep blue accent (light); larger, heavier type; 2px borders on every
|
||||
control and panel; flat surfaces with no shadows; 6px corners; 48px targets on
|
||||
every platform; and a 3px keyboard focus ring with an offset.
|
||||
|
||||
Files: `lib/ui/theme/high_contrast_{palette,theme,controls,typography}.dart`,
|
||||
`lib/ui/theme/design_focus_ring.dart`,
|
||||
`lib/features/chat/ui/transcript/boxed/`.
|
||||
|
||||
## Tokens added to `AppDesignTokens` (defaults keep every other design)
|
||||
|
||||
| token | default | High contrast | read by |
|
||||
| --- | --- | --- | --- |
|
||||
| `stroke` | 1 | 2 | `frameSide`, `GlassPill` (flat), settings groups, avatars, stack labels, graph edges, floating windows, boxed transcript |
|
||||
| `ringStroke` | 2 | 3 | the send button's usage ring |
|
||||
| `focusRing` (`FocusRingStyle`: color, halo, width, offset) | null | accent, page halo, 3px, 2px offset | `DesignFocusRing` |
|
||||
| `largeTargets` | false | true | `prefersCompactHitTargets` (false: touch rows and 48px targets on a desktop) |
|
||||
| `minContrast` | null | 4.5 | chat colours moved to 4.5:1 against the page (`colorWithContrast`), no chat tints (list rows, header bar, stack labels outline instead), solid usage-ring track, avatars' marks and frames at full strength |
|
||||
| `windowRadius` | null (12) | 6 | floating windows' corners |
|
||||
| `snapSwitch` | false | true | `AppDesignController.themeAnimationDuration`: a live switch into or out of the design snaps (no grey-on-grey half-blend; its larger component sizes have nothing to blend from, and with the blend the browser bench's live-switch scenario hung under skwasm twice) |
|
||||
|
||||
Styles added: `TranscriptStyle.boxed`, `SelectedRowStyle.inverted`.
|
||||
`AppDesignTokens.inverseTheme(theme)` gives the same design in the opposite
|
||||
brightness (cached), which an inverted surface draws its content under.
|
||||
|
||||
## Surfaces
|
||||
|
||||
- Palette: every surface container is the page; panels part by borders.
|
||||
`secondaryContainer` is the ink, so selected things (navigation indicator,
|
||||
chips, segmented buttons, list tiles) are inverted.
|
||||
- Type: body 17/16/14px at weight 500, labels 16/14/13px and titles at 600.
|
||||
Sizes stay theme roles, so text scaling and the system's bold-text setting
|
||||
apply. Button text keeps the theme's `labelLarge` (a button style's own
|
||||
text style would fail to blend during a live design switch).
|
||||
- Controls: filled/outlined/elevated/segmented buttons, chips, fields, search
|
||||
bars, checkboxes and switches have 2px borders; fields take 3px of the
|
||||
accent when focused; text and icon buttons stay unframed. Disabled ink is
|
||||
`#8F8F8F` on black (6.5:1) and `#6E6E6E` on white (5.1:1).
|
||||
- Floating pieces: menus, dialogs, sheets framed 2px, no elevation; tooltips
|
||||
inverted, 16px weight 600, padded 12x8, framed in the page colour; snack
|
||||
bars inverted with a 2px edge and the inverse accent for actions.
|
||||
- Focus: `DesignFocusRing` (inserted in the three `MaterialApp.builder`s)
|
||||
draws the ring around `FocusManager.primaryFocus` over the whole app, a
|
||||
page-coloured halo inside a 3px accent ring 2px outside the control; a text
|
||||
field's ring goes round its whole decorated box. Like `:focus-visible` it
|
||||
shows after a key press and hides on any pointer press. It tracks a
|
||||
scrolling control with post-frame checks only (no frames scheduled).
|
||||
- Chat (`boxed`): the operator's turn under a bold "You" label in a box with
|
||||
a 2px ink frame and a 6px bar in the chat's colour (ink when none), painted
|
||||
in one pass (`BoxedFramePainter`, canvas clip, no layer); the agent's
|
||||
answer plain on the page; activity as one bordered block, a row per tool
|
||||
with an icon and a status word ("Done", "Failed", "Running") in a status
|
||||
colour at 7:1 in one aligned column; agent follow-ups as cards framed 2px in
|
||||
the secondary ink; the header bar is not tinted.
|
||||
- Lists: the open row is inverted (ink fill, page text, opposite-brightness
|
||||
theme so its status colours keep contrast) with a 6px bar; unselected chat
|
||||
rows show their colour only as their bar and avatar frame.
|
||||
- Graph: edges as heavy as the frames (2px), the selected node inverted;
|
||||
edge hover and tooltip unchanged (accent glow at 2.5x the edge, inverse
|
||||
tooltip).
|
||||
- Phone chat stack: discs and labels flat in 6px corners; a label's chat
|
||||
colour is a 3px outline, the Add disc framed in the full accent.
|
||||
- Floating windows: 6px corners and a 2px ink outline.
|
||||
|
||||
## Still default
|
||||
|
||||
- Icon buttons in toolbars have no frame (strong hover/press overlays and the
|
||||
focus ring instead); text buttons are unframed.
|
||||
- Floating window title bars keep their 40px compact icon buttons.
|
||||
- Graph node status captions keep their fixed 12px size (preview scale).
|
||||
- Markdown, code blocks and links keep the shared rendering (links were
|
||||
already underlined).
|
||||
- The system's high-contrast setting does not switch designs by itself; the
|
||||
design is chosen per device like the others.
|
||||
|
||||
## Contrast (WCAG 2, against the page)
|
||||
|
||||
| pair | dark | light |
|
||||
| --- | --- | --- |
|
||||
| ink | 21:1 | 21:1 |
|
||||
| secondary ink | 13.6:1 | 12.6:1 |
|
||||
| accent | 14.9:1 | 9.4:1 |
|
||||
| text on accent | 14.9:1 | 9.4:1 |
|
||||
| error | 7.6:1 | 7.4:1 |
|
||||
| status green / cyan / magenta | 15.7 / 13.7 / 9.8 | 7.4 / 7.4 / 8.5 |
|
||||
| warning (usage ring) | 10.2:1 | 7.8:1 |
|
||||
| rules | 7.8:1 | 7.0:1 |
|
||||
| disabled | 6.5:1 | 5.1:1 |
|
||||
| chat colours | >= 4.5:1 (tested for all 13) | >= 4.5:1 |
|
||||
|
||||
`test/ui/theme/high_contrast_design_test.dart` computes and asserts these.
|
||||
|
||||
## Perf (tool/perf/design_bench.mjs, skwasm CPU, medians of 3)
|
||||
|
||||
| scenario | Default build/raster ms per frame | High contrast |
|
||||
| --- | --- | --- |
|
||||
| scroll | 8.99 / 56.96 | 3.65 / 14.16 |
|
||||
| switch chats | 10.4 / 52.72 | 4.45 / 15.41 |
|
||||
| runs | 2.69 / 12.18 | 2.48 / 7.06 |
|
||||
| graph | 2.04 / 17.41 | 2.84 / 19.44 |
|
||||
| live design switches | 14.36 / 22.19 | 5.44 / 13.15 (heap +0.57 MB) |
|
||||
|
||||
PASS; no off-origin fetch beyond Default's. Flat pieces, no blur, one
|
||||
painter per boxed turn. The chat list's default click points still hit
|
||||
rows 1-3 at 1280x800 (rows at y 124-232, 232-313, 313-393).
|
||||
|
||||
## Tests
|
||||
|
||||
- `test/ui/theme/high_contrast_design_test.dart`: tokens, pages, every
|
||||
contrast pair above computed and asserted (7:1 / 4.5:1), all chat colours,
|
||||
flat bordered surfaces, type, inverse theme, the snap, desktop targets, and
|
||||
every other design's new tokens at their defaults.
|
||||
- `test/ui/theme/high_contrast_widgets_test.dart`: focus ring (3px, offset,
|
||||
halo, text-field box, hidden after a pointer press, absent elsewhere),
|
||||
48px targets on Linux, boxed transcript (You box, Done/Failed, aligned
|
||||
names), inverted row vs Terminal's unchanged row, 200% text scale on a
|
||||
360px phone with no overflow (light and dark).
|
||||
- `test/ui/theme/high_contrast_switch_test.dart` and High contrast added to
|
||||
`compact_switch_test.dart`: per-frame switches to and from every design.
|
||||
@@ -151,7 +151,7 @@ void main() {
|
||||
);
|
||||
expect(painter.circle, circle.width);
|
||||
expect(
|
||||
painter.radius - ChatUsageRingPainter.stroke / 2,
|
||||
painter.radius - painter.stroke / 2,
|
||||
circle.width / 2 + ChatUsageRingPainter.gap,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -107,7 +107,8 @@ void main() {
|
||||
AppDesign.terminal,
|
||||
AppDesign.paper,
|
||||
AppDesign.notebook,
|
||||
// Glass blends with the comfortable designs and snaps to Compact.
|
||||
AppDesign.highContrast,
|
||||
// Glass snaps in and out (snapSwitch), to and from Compact too.
|
||||
AppDesign.glass,
|
||||
AppDesign.compact,
|
||||
AppDesign.glass,
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.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/platform.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
import 'package:pipelines_app/ui/theme/high_contrast_palette.dart';
|
||||
|
||||
ThemeData _theme(AppDesign design, Brightness brightness) =>
|
||||
brightness == Brightness.dark ? design.dark() : design.light();
|
||||
|
||||
/// Fails with the pair's name and ratio when [fg] on [bg] is below [min].
|
||||
void _expectContrast(String pair, Color fg, Color bg, double min) {
|
||||
final ratio = contrastRatio(fg, bg);
|
||||
expect(
|
||||
ratio,
|
||||
greaterThanOrEqualTo(min),
|
||||
reason: '$pair: ${ratio.toStringAsFixed(2)}:1, wanted $min:1',
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('High contrast is listed with a stable id, a label and one line', () {
|
||||
expect(AppDesign.values, contains(AppDesign.highContrast));
|
||||
expect(AppDesign.fromId('high-contrast'), AppDesign.highContrast);
|
||||
expect(AppDesign.highContrast.label, 'High contrast');
|
||||
expect(AppDesign.highContrast.description, isNot(contains('\n')));
|
||||
expect(AppDesign.highContrast.usesInterfaceFont, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'tokens: boxed transcript, inverted row, 6px corners, 2px frames, a '
|
||||
'thicker usage ring, a 3px focus ring, 48px targets, a contrast floor',
|
||||
() {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = theme.extension<AppDesignTokens>()!;
|
||||
expect(tokens.design, AppDesign.highContrast);
|
||||
expect(tokens.transcript, TranscriptStyle.boxed);
|
||||
expect(tokens.selectedRow, SelectedRowStyle.inverted);
|
||||
expect(tokens.composer, ComposerStyle.pill);
|
||||
expect(tokens.radius, 6);
|
||||
expect(tokens.flat, isTrue);
|
||||
expect(tokens.stroke, 2);
|
||||
expect(tokens.frameSide, BorderSide(color: scheme.outline, width: 2));
|
||||
expect(tokens.ringStroke, 3);
|
||||
expect(tokens.focusRing?.width, 3);
|
||||
expect(tokens.focusRing?.offset, greaterThan(0));
|
||||
expect(tokens.focusRing?.color, scheme.primary);
|
||||
expect(tokens.largeTargets, isTrue);
|
||||
expect(tokens.minContrast, highContrastMinimum);
|
||||
expect(tokens.windowRadius, 6);
|
||||
expect(tokens.snapSwitch, isTrue);
|
||||
expect(tokens.ansi, isNotNull);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test('pages are pure black and pure white, every container the page', () {
|
||||
final dark = AppDesign.highContrast.dark().colorScheme;
|
||||
final light = AppDesign.highContrast.light().colorScheme;
|
||||
expect(dark.surface, const Color(0xFF000000));
|
||||
expect(dark.onSurface, const Color(0xFFFFFFFF));
|
||||
expect(light.surface, const Color(0xFFFFFFFF));
|
||||
expect(light.onSurface, const Color(0xFF000000));
|
||||
for (final scheme in [dark, light]) {
|
||||
for (final container in [
|
||||
scheme.surfaceContainerLowest,
|
||||
scheme.surfaceContainerLow,
|
||||
scheme.surfaceContainer,
|
||||
scheme.surfaceContainerHigh,
|
||||
scheme.surfaceContainerHighest,
|
||||
]) {
|
||||
expect(container, scheme.surface);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
group('contrast', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
test('$brightness: body text and status words reach 7:1, everything '
|
||||
'else 4.5:1', () {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final s = theme.colorScheme;
|
||||
final page = s.surface;
|
||||
// WCAG AAA (7:1): reading text, the accent, errors and every
|
||||
// status colour a word is written in.
|
||||
for (final (name, fg, bg) in [
|
||||
('ink on page', s.onSurface, page),
|
||||
('secondary ink on page', s.onSurfaceVariant, page),
|
||||
('accent on page', s.primary, page),
|
||||
('text on accent', s.onPrimary, s.primary),
|
||||
('error on page', s.error, page),
|
||||
('error text on its container', s.onErrorContainer, s.errorContainer),
|
||||
('inverted row text', s.onSecondaryContainer, s.secondaryContainer),
|
||||
('tooltip/snack bar text', s.onInverseSurface, s.inverseSurface),
|
||||
('snack bar action', s.inversePrimary, s.inverseSurface),
|
||||
('green status', theme.ext.ansi!.green, page),
|
||||
('cyan status', theme.ext.ansi!.cyan, page),
|
||||
('yellow status', theme.ext.ansi!.yellow, page),
|
||||
('red status', theme.ext.ansi!.red, page),
|
||||
('magenta status', theme.ext.ansi!.magenta, page),
|
||||
('blue status', theme.ext.ansi!.blue, page),
|
||||
]) {
|
||||
_expectContrast(name, fg, bg, highContrastText);
|
||||
}
|
||||
// AA (4.5:1) for everything else, disabled text included.
|
||||
for (final (name, fg, bg) in [
|
||||
('control border', s.outline, page),
|
||||
('rule', s.outlineVariant, page),
|
||||
('warning (usage ring)', s.tertiary, page),
|
||||
('text on warning', s.onTertiary, s.tertiary),
|
||||
('text on error', s.onError, s.error),
|
||||
('disabled text', theme.disabledColor, page),
|
||||
('hint text', theme.hintColor, page),
|
||||
('focus ring', theme.ext.focusRing!.color, page),
|
||||
]) {
|
||||
_expectContrast(name, fg, bg, highContrastMinimum);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$brightness: every chat colour reaches 4.5:1 on the page, '
|
||||
'and keeps its hue', (tester) async {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
late BuildContext context;
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: theme,
|
||||
child: Builder(
|
||||
builder: (c) {
|
||||
context = c;
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final name in chatColorNames) {
|
||||
final shade = chatColorShade(context, name)!;
|
||||
_expectContrast(
|
||||
'chat colour $name',
|
||||
shade,
|
||||
theme.scaffoldBackgroundColor,
|
||||
highContrastMinimum,
|
||||
);
|
||||
}
|
||||
// The orange's hue survives the darkening on white.
|
||||
final orange = HSVColor.fromColor(chatColorShade(context, 'orange')!);
|
||||
expect(orange.hue, inInclusiveRange(15, 45));
|
||||
});
|
||||
}
|
||||
|
||||
test('colorWithContrast moves away from the page, never past it', () {
|
||||
const yellow = Color(0xFFFFEB3B);
|
||||
final onWhite = colorWithContrast(yellow, const Color(0xFFFFFFFF), 4.5);
|
||||
expect(contrastRatio(onWhite, const Color(0xFFFFFFFF)), greaterThan(4.5));
|
||||
expect(onWhite.computeLuminance(), lessThan(yellow.computeLuminance()));
|
||||
// Already enough: unchanged.
|
||||
expect(
|
||||
colorWithContrast(yellow, const Color(0xFF000000), 4.5),
|
||||
same(yellow),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('flat, bordered surfaces: no elevation, 2px borders, 6px corners', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final scheme = theme.colorScheme;
|
||||
expect(theme.cardTheme.elevation, 0);
|
||||
expect(theme.dialogTheme.elevation, 0);
|
||||
expect(theme.popupMenuTheme.elevation, 0);
|
||||
expect(theme.snackBarTheme.elevation, 0);
|
||||
expect(theme.floatingActionButtonTheme.elevation, 0);
|
||||
expect(theme.appBarTheme.scrolledUnderElevation, 0);
|
||||
for (final shape in [
|
||||
theme.cardTheme.shape,
|
||||
theme.dialogTheme.shape,
|
||||
theme.popupMenuTheme.shape,
|
||||
theme.snackBarTheme.shape,
|
||||
]) {
|
||||
final border = shape! as RoundedRectangleBorder;
|
||||
expect(border.borderRadius, BorderRadius.circular(6));
|
||||
expect(border.side.width, 2);
|
||||
}
|
||||
expect(
|
||||
(theme.cardTheme.shape! as RoundedRectangleBorder).side.color,
|
||||
scheme.outline,
|
||||
);
|
||||
// Tooltips: large, inverted, framed.
|
||||
final tip = theme.tooltipTheme.decoration! as BoxDecoration;
|
||||
expect(tip.color, scheme.inverseSurface);
|
||||
expect(theme.tooltipTheme.textStyle!.fontSize, greaterThanOrEqualTo(16));
|
||||
// Fields: 2px, 3px of the accent while focused.
|
||||
final field = theme.inputDecorationTheme.border!;
|
||||
final idle = WidgetStateProperty.resolveAs<InputBorder>(field, {});
|
||||
final focused = WidgetStateProperty.resolveAs<InputBorder>(field, {
|
||||
WidgetState.focused,
|
||||
});
|
||||
expect(idle.borderSide.width, 2);
|
||||
expect(focused.borderSide.width, 3);
|
||||
expect(focused.borderSide.color, scheme.primary);
|
||||
// Outlined and filled buttons framed at 2px; disabled ones in the
|
||||
// disabled ink, still 4.5:1.
|
||||
final outlined = theme.outlinedButtonTheme.style!;
|
||||
expect(outlined.side!.resolve({})!.width, 2);
|
||||
expect(
|
||||
outlined.foregroundColor!.resolve({WidgetState.disabled}),
|
||||
theme.disabledColor,
|
||||
);
|
||||
expect(theme.filledButtonTheme.style!.side!.resolve({})!.width, 2);
|
||||
}
|
||||
});
|
||||
|
||||
test('larger, heavier type: body 16-17px at weight 500', () {
|
||||
final text = AppDesign.highContrast.light().textTheme;
|
||||
expect(text.bodyLarge!.fontSize, 17);
|
||||
expect(text.bodyMedium!.fontSize, 16);
|
||||
expect(text.bodySmall!.fontSize, greaterThanOrEqualTo(14));
|
||||
for (final style in [text.bodyLarge, text.bodyMedium, text.bodySmall]) {
|
||||
expect(style!.fontWeight, FontWeight.w500);
|
||||
}
|
||||
expect(text.labelSmall!.fontSize, greaterThanOrEqualTo(13));
|
||||
});
|
||||
|
||||
test('the inverse theme is the same design in the other brightness', () {
|
||||
final dark = AppDesign.highContrast.dark();
|
||||
final inverse = AppDesignTokens.inverseTheme(dark);
|
||||
expect(inverse.brightness, Brightness.light);
|
||||
expect(
|
||||
inverse.extension<AppDesignTokens>()!.design,
|
||||
AppDesign.highContrast,
|
||||
);
|
||||
expect(AppDesignTokens.inverseTheme(dark), same(inverse));
|
||||
});
|
||||
|
||||
group('the others are unchanged', () {
|
||||
test('Classic is the original theme; new tokens default for every other '
|
||||
'design', () {
|
||||
expect(AppDesign.standard.light(), appLightTheme());
|
||||
expect(AppDesign.standard.dark(), appDarkTheme());
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
for (final brightness in Brightness.values) {
|
||||
final tokens =
|
||||
_theme(design, brightness).extension<AppDesignTokens>() ??
|
||||
AppDesignTokens.standard;
|
||||
expect(tokens.stroke, 1, reason: design.id);
|
||||
expect(tokens.ringStroke, 2, reason: design.id);
|
||||
expect(tokens.focusRing, isNull, reason: design.id);
|
||||
expect(tokens.largeTargets, isFalse, reason: design.id);
|
||||
expect(tokens.minContrast, isNull, reason: design.id);
|
||||
expect(tokens.windowRadius, isNull, reason: design.id);
|
||||
// Glass snaps too: its clear pages do not blend with an opaque
|
||||
// design's.
|
||||
expect(
|
||||
tokens.snapSwitch,
|
||||
design == AppDesign.glass,
|
||||
reason: design.id,
|
||||
);
|
||||
expect(tokens.transcript, isNot(TranscriptStyle.boxed));
|
||||
expect(tokens.selectedRow, isNot(SelectedRowStyle.inverted));
|
||||
final frame = tokens.frame;
|
||||
expect(
|
||||
tokens.frameSide,
|
||||
frame == null ? isNull : BorderSide(color: frame),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('a switch into or out of High contrast snaps; Paper to Terminal '
|
||||
'still blends', () async {
|
||||
final designs = AppDesignController(store: MemoryAppDesignStore());
|
||||
await designs.select(AppDesign.paper);
|
||||
await designs.select(AppDesign.terminal);
|
||||
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
|
||||
await designs.select(AppDesign.highContrast);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
await designs.select(AppDesign.paper);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
});
|
||||
|
||||
testWidgets('touch targets on a desktop only under High contrast', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
final compact = <AppDesign, bool>{};
|
||||
for (final design in AppDesign.values) {
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: design.light(),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
compact[design] = prefersCompactHitTargets(context);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
expect(compact[AppDesign.highContrast], isFalse);
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
expect(compact[design], isTrue, reason: design.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
extension on ThemeData {
|
||||
AppDesignTokens get ext => extension<AppDesignTokens>()!;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
|
||||
final _rows = transcriptRows([
|
||||
for (var i = 0; i < 6; i++) ...[
|
||||
{
|
||||
'id': 'u$i',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Step $i'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a$i',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'tool',
|
||||
'id': 't$i',
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'command': 'go test'},
|
||||
},
|
||||
},
|
||||
{'type': 'text', 'text': 'Fixed `x`.\n\n- one\n\n```go\nreturn 1\n```'},
|
||||
],
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
/// A live design switch to and from High contrast animates the theme (or
|
||||
/// snaps it, beside a dense design) without an error in any frame: a
|
||||
/// component text style from the unlocalized text theme cannot blend with
|
||||
/// another design's default (High contrast sets none on buttons).
|
||||
void main() {
|
||||
testWidgets('switching to and from High contrast lerps every frame cleanly', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
final design = ValueNotifier(AppDesign.highContrast);
|
||||
await tester.pumpWidget(
|
||||
ValueListenableBuilder<AppDesign>(
|
||||
valueListenable: design,
|
||||
builder: (_, d, _) => MaterialApp(
|
||||
theme: d.dark(),
|
||||
darkTheme: d.dark(),
|
||||
home: Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New run'),
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
NavigationRail(
|
||||
destinations: const [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('a'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('b'),
|
||||
),
|
||||
],
|
||||
selectedIndex: 0,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
||||
IconButton.filled(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
FilledButton(onPressed: () {}, child: const Text('f')),
|
||||
OutlinedButton(onPressed: () {}, child: const Text('o')),
|
||||
TextButton(onPressed: () {}, child: const Text('t')),
|
||||
MenuItemButton(onPressed: () {}, child: const Text('m')),
|
||||
const Badge(label: Text('3'), child: Icon(Icons.add)),
|
||||
const Tooltip(message: 'tip', child: Text('tip')),
|
||||
const DefaultTabController(
|
||||
length: 2,
|
||||
child: TabBar(
|
||||
tabs: [
|
||||
Tab(text: 'a'),
|
||||
Tab(text: 'b'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: true, onChanged: (_) {}),
|
||||
const ListTile(title: Text('t'), subtitle: Text('s')),
|
||||
const TextField(),
|
||||
Chip(label: const Text('c'), onDeleted: () {}),
|
||||
SegmentedButton<int>(
|
||||
segments: const [
|
||||
ButtonSegment(value: 1, label: Text('one')),
|
||||
ButtonSegment(value: 2, label: Text('two')),
|
||||
],
|
||||
selected: const {1},
|
||||
),
|
||||
for (final row in _rows) ChatMessageView(row: row),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var round = 0; round < 3; round++) {
|
||||
for (final other in [
|
||||
for (final d in AppDesign.values)
|
||||
if (d != AppDesign.highContrast) ...[d, AppDesign.highContrast],
|
||||
]) {
|
||||
design.value = other;
|
||||
for (var f = 0; f < 20; f++) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
final e = tester.takeException();
|
||||
if (e != null) fail('to ${other.id} frame $f: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.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/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_design_section.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/design_focus_ring.dart';
|
||||
|
||||
JsonMap _tool(String id, String status) => {
|
||||
'type': 'tool',
|
||||
'id': id,
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': status,
|
||||
'input': {'command': 'go test ./internal/notes/...'},
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'ok notes 0.2s'},
|
||||
],
|
||||
if (status == 'error') 'error': {'message': 'exit status 1'},
|
||||
},
|
||||
};
|
||||
|
||||
/// An operator turn, then an answer with a passing and a failing tool call.
|
||||
final List<JsonMap> _rows = transcriptRows([
|
||||
{
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'text',
|
||||
'text': 'The release notes job fails on Windows paths. Fix it.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
_tool('t1', 'completed'),
|
||||
_tool('t2', 'error'),
|
||||
{'type': 'text', 'text': 'Fixed: `filepath.Join` now.'},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
/// [child] under [design]'s theme at [width], with [textScale], inside the
|
||||
/// focus ring host the app's builders use.
|
||||
Widget _host(
|
||||
Widget child, {
|
||||
AppDesign design = AppDesign.highContrast,
|
||||
Brightness brightness = Brightness.dark,
|
||||
double textScale = 1,
|
||||
}) => MaterialApp(
|
||||
theme: design.light(),
|
||||
darkTheme: design.dark(),
|
||||
themeMode: brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light,
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void _size(WidgetTester tester, Size size) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
FocusRingPainter? _ring(WidgetTester tester) => tester
|
||||
.widgetList<CustomPaint>(find.byType(CustomPaint))
|
||||
.map((paint) => paint.painter)
|
||||
.whereType<FocusRingPainter>()
|
||||
.firstOrNull;
|
||||
|
||||
void main() {
|
||||
group('focus ring', () {
|
||||
testWidgets('a 3px ring with an offset goes round the control with '
|
||||
'keyboard focus', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(_ring(tester)?.rect.value, isNull);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final ring = _ring(tester)!;
|
||||
final rect = ring.rect.value!;
|
||||
final button = tester.getRect(find.byType(FilledButton));
|
||||
// The ring's target is the button itself (within its tap padding).
|
||||
expect(button.inflate(1).contains(rect.topLeft), isTrue);
|
||||
expect(button.inflate(1).contains(rect.bottomRight), isTrue);
|
||||
expect(ring.style.width, 3);
|
||||
expect(ring.style.offset, greaterThan(0));
|
||||
final scheme = AppDesign.highContrast.dark().colorScheme;
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(w) => w is CustomPaint && w.painter is FocusRingPainter,
|
||||
),
|
||||
paints
|
||||
..rrect(color: scheme.surface, strokeWidth: ring.style.offset)
|
||||
..rrect(color: scheme.primary, strokeWidth: 3),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a text field rings its whole decorated box', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(const Center(child: SizedBox(width: 300, child: TextField()))),
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final rect = _ring(tester)!.rect.value!;
|
||||
expect(rect.size, tester.getSize(find.byType(InputDecorator)));
|
||||
});
|
||||
|
||||
testWidgets('a pointer press hides the ring, as :focus-visible does; '
|
||||
'no ring under another design', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_ring(tester)!.rect.value, isNotNull);
|
||||
await tester.tap(find.byType(FilledButton));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_ring(tester)!.rect.value, isNull);
|
||||
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
design: design,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
expect(_ring(tester), isNull, reason: design.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('every control keeps a 48px target on a desktop', (tester) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
_size(tester, const Size(800, 900));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [
|
||||
Wrap(
|
||||
children: [
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
||||
TextButton(onPressed: () {}, child: const Text('Ok')),
|
||||
OutlinedButton(onPressed: () {}, child: const Text('Ok')),
|
||||
FilledButton(onPressed: () {}, child: const Text('Ok')),
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
Switch(value: true, onChanged: (_) {}),
|
||||
ActionChip(label: const Text('Chip'), onPressed: () {}),
|
||||
FilterChip(
|
||||
label: const Text('Filter'),
|
||||
selected: true,
|
||||
onSelected: (_) {},
|
||||
),
|
||||
],
|
||||
),
|
||||
const ListTile(title: Text('Tile')),
|
||||
MenuItemButton(onPressed: () {}, child: const Text('Item')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final type in [
|
||||
IconButton,
|
||||
TextButton,
|
||||
OutlinedButton,
|
||||
FilledButton,
|
||||
Checkbox,
|
||||
Switch,
|
||||
ActionChip,
|
||||
FilterChip,
|
||||
ListTile,
|
||||
MenuItemButton,
|
||||
]) {
|
||||
final size = tester.getSize(find.byType(type).first);
|
||||
expect(size.height, greaterThanOrEqualTo(48), reason: '$type');
|
||||
expect(size.width, greaterThanOrEqualTo(48), reason: '$type');
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
group('boxed transcript', () {
|
||||
testWidgets('the operator\'s turn is a framed box under "You"; tools are '
|
||||
'bordered rows that say Done and Failed', (tester) async {
|
||||
_size(tester, const Size(900, 900));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [for (final row in _rows) ChatMessageView(row: row)],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-boxed-quote')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-boxed-quote-label')), findsOneWidget);
|
||||
expect(find.text('You'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-boxed-activity')), findsOneWidget);
|
||||
expect(find.byKey(const Key('boxed-status-done')), findsOneWidget);
|
||||
expect(find.byKey(const Key('boxed-status-failed')), findsOneWidget);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
expect(find.text('Failed'), findsOneWidget);
|
||||
// The activity block is one big target.
|
||||
final block = tester.getSize(
|
||||
find.byKey(const Key('chat-boxed-activity')),
|
||||
);
|
||||
expect(block.height, greaterThanOrEqualTo(48));
|
||||
// The two tool names start at one column, whatever the status word.
|
||||
final names = tester
|
||||
.widgetList<RichText>(find.byType(RichText))
|
||||
.where((t) => t.text.toPlainText().startsWith('Bash'));
|
||||
final starts = {
|
||||
for (final name in names) tester.getTopLeft(find.byWidget(name)).dx,
|
||||
};
|
||||
expect(starts, hasLength(1));
|
||||
// No bubble fill: the agent's answer sits on the page.
|
||||
expect(find.byType(ChatUserBubble), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('inverted open row', () {
|
||||
Widget rows({AppDesign design = AppDesign.highContrast}) => _host(
|
||||
Column(
|
||||
children: [
|
||||
AppListRow(
|
||||
key: const Key('open'),
|
||||
selected: true,
|
||||
leading: const AppListAvatar(child: Icon(Icons.check)),
|
||||
title: const Text('Release train run'),
|
||||
subtitle: const Text('release-train · 30m'),
|
||||
time: '09:12',
|
||||
onTap: () {},
|
||||
),
|
||||
AppListRow(
|
||||
key: const Key('closed'),
|
||||
title: const Text('Nightly docs run'),
|
||||
subtitle: const Text('nightly-docs · 3m'),
|
||||
time: '23:00',
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
design: design,
|
||||
);
|
||||
|
||||
testWidgets('the open row is the ink with the page as its text, and a '
|
||||
'thicker bar', (tester) async {
|
||||
_size(tester, const Size(500, 400));
|
||||
await tester.pumpWidget(rows());
|
||||
final dark = AppDesign.highContrast.dark();
|
||||
final surface = tester.widget<Material>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('open')),
|
||||
matching: find.byKey(appListRowSurfaceKey),
|
||||
),
|
||||
);
|
||||
expect(surface.color, dark.colorScheme.onSurface);
|
||||
final title = tester.widget<DefaultTextStyle>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.text('Release train run'),
|
||||
matching: find.byType(DefaultTextStyle),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(title.style.color, dark.colorScheme.surface);
|
||||
final bar = tester.widget<DecoratedBox>(
|
||||
find.byKey(appListRowSelectionKey),
|
||||
);
|
||||
final border = (bar.decoration as BoxDecoration).border!;
|
||||
expect((border as BorderDirectional).start.width, 6);
|
||||
// The closed row keeps the page and the ink.
|
||||
final closed = tester.widget<DefaultTextStyle>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.text('Nightly docs run'),
|
||||
matching: find.byType(DefaultTextStyle),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(closed.style.color, dark.colorScheme.onSurface);
|
||||
});
|
||||
|
||||
testWidgets('Terminal\'s open row is unchanged: washed and framed', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(500, 400));
|
||||
await tester.pumpWidget(rows(design: AppDesign.terminal));
|
||||
final bar = tester.widget<DecoratedBox>(
|
||||
find.byKey(appListRowSelectionKey),
|
||||
);
|
||||
final border =
|
||||
(bar.decoration as BoxDecoration).border! as BorderDirectional;
|
||||
expect(border.start.width, kAppListRowBarWidth);
|
||||
expect(border.top.width, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('200% text scale: nothing overflows', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('transcript, rows and the design picker on a phone '
|
||||
'(${brightness.name})', (tester) async {
|
||||
_size(tester, const Size(360, 2400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [
|
||||
for (final row in _rows) ChatMessageView(row: row),
|
||||
AppListRow(
|
||||
selected: true,
|
||||
leading: const AppListAvatar(child: Icon(Icons.check)),
|
||||
title: const Text('Release train run with a long title'),
|
||||
subtitle: const Text('release-train · 30m 0s · v4'),
|
||||
detail: const Text('Release 2.4 shipped; notes published.'),
|
||||
time: '09:12',
|
||||
menu: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.more_vert),
|
||||
),
|
||||
onTap: () {},
|
||||
),
|
||||
SettingsDesignSection(
|
||||
controller: AppDesignController(
|
||||
store: MemoryAppDesignStore(AppDesign.highContrast.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
brightness: brightness,
|
||||
textScale: 2,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
expect(find.text('High contrast'), findsWidgets);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user