Files
pipelines/app/lib/ui/theme/app_design_tokens.dart
T
alan 8ed3998dd5 Design: Terminal is the default when none is stored; Default is now Classic
An unset (or unknown) design id resolves to Terminal, in the controller's
initial value, AppDesign.fromId and the boot spinner. A stored choice,
including Classic's stable 'default' id, is respected. The picker calls the
original Material look Classic so no row reads 'Default'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:33:05 +00:00

215 lines
6.7 KiB
Dart

import 'package:flutter/material.dart';
import 'app_design.dart';
import 'app_design_styles.dart';
export 'app_design_styles.dart';
/// The muted ANSI-style accents a design names for status and roles. The
/// Classic design leaves them to its colour scheme; Terminal sets them, and
/// Paper sets ink-toned ones.
@immutable
class AnsiAccents {
const AnsiAccents({
required this.green,
required this.cyan,
required this.yellow,
required this.red,
required this.magenta,
required this.blue,
});
final Color green;
final Color cyan;
final Color yellow;
final Color red;
final Color magenta;
final Color blue;
@override
bool operator ==(Object other) =>
other is AnsiAccents &&
other.green == green &&
other.cyan == cyan &&
other.yellow == yellow &&
other.red == red &&
other.magenta == magenta &&
other.blue == blue;
@override
int get hashCode => Object.hash(green, cyan, yellow, red, magenta, blue);
}
/// The design-specific facts widgets read instead of hard-coding one look:
/// corner shapes, whether surfaces are flat, frame colour, how the chat
/// transcript, the composer and the open list row are drawn, and the reading
/// typography. Every theme an [AppDesign] builds carries one; a theme without
/// one (a test's bare `ThemeData`) reads as [standard].
///
/// Adding a design: every field has a default that keeps the Classic look,
/// so a new design sets only what it changes. Widgets branch on the named
/// styles ([transcript], [composer], [selectedRow]) rather than on [design],
/// so two designs can share a behaviour.
@immutable
class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
const AppDesignTokens({
required this.design,
this.radius,
this.flat = false,
this.frame,
this.panel,
this.ansi,
this.promptGlyph = '>',
this.transcript = TranscriptStyle.bubbles,
this.composer = ComposerStyle.pill,
this.selectedRow = SelectedRowStyle.tonal,
this.reading = const ReadingType(),
this.chatColorSaturation = 1,
});
/// The Classic design: every widget keeps its own shapes.
static const AppDesignTokens standard = AppDesignTokens(
design: AppDesign.standard,
);
final AppDesign design;
/// The corner radius of framed surfaces (cards, pills, the composer,
/// bubbles, thumbnails, badges); null keeps each widget's own shape.
final double? radius;
/// Whether surfaces are flat: no frosted glass, blur, highlight or shadow.
final bool flat;
/// The 1px frame colour around flat surfaces; null keeps each widget's own.
final Color? frame;
/// The fill of a flat design's own panels (settings groups, floating bars,
/// cards a widget draws itself); null keeps `surfaceContainerLow`.
final Color? panel;
/// The design's ANSI-style accents; null for a design that uses its colour
/// scheme's roles.
final AnsiAccents? ansi;
/// The glyph before the operator's prompt line and the composer's field.
final String promptGlyph;
/// How the chat transcript draws the operator's and the agent's turns.
final TranscriptStyle transcript;
/// How the chat composer frames its writing area.
final ComposerStyle composer;
/// How a list marks its open row.
final SelectedRowStyle selectedRow;
/// The face, line height and measure of reading text (chat, documents).
final ReadingType reading;
/// How much of a chat colour's saturation the transcript keeps: 1 for the
/// palette as is, lower to quieten it towards ink.
final double chatColorSaturation;
/// Whether the transcript draws prompt and tool lines rather than bubbles.
bool get terminal => transcript == TranscriptStyle.prompt;
/// The tokens of the theme at [context]; [standard] when it has none.
static AppDesignTokens of(BuildContext context) =>
Theme.of(context).extension<AppDesignTokens>() ?? standard;
/// [designed] as this design draws it: the widget's own shape, or a
/// rectangle with [radius] corners.
OutlinedBorder shape(OutlinedBorder designed) {
final r = radius;
if (r == null) return designed;
return RoundedRectangleBorder(borderRadius: BorderRadius.circular(r));
}
/// [designed] corners, or [radius] corners under a design that sets it.
BorderRadius corners(BorderRadius designed) {
final r = radius;
return r == null ? designed : BorderRadius.circular(r);
}
/// [designed] (a widget's own fill) or, under a flat design, its [panel].
Color panelFill(ColorScheme scheme, Color designed) =>
flat ? panel ?? scheme.surfaceContainerLow : designed;
/// 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);
}
@override
AppDesignTokens copyWith({
AppDesign? design,
double? radius,
bool? flat,
Color? frame,
Color? panel,
AnsiAccents? ansi,
String? promptGlyph,
TranscriptStyle? transcript,
ComposerStyle? composer,
SelectedRowStyle? selectedRow,
ReadingType? reading,
double? chatColorSaturation,
}) => AppDesignTokens(
design: design ?? this.design,
radius: radius ?? this.radius,
flat: flat ?? this.flat,
frame: frame ?? this.frame,
panel: panel ?? this.panel,
ansi: ansi ?? this.ansi,
promptGlyph: promptGlyph ?? this.promptGlyph,
transcript: transcript ?? this.transcript,
composer: composer ?? this.composer,
selectedRow: selectedRow ?? this.selectedRow,
reading: reading ?? this.reading,
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
);
// Value equality keeps a rebuilt theme equal to the one it replaces, so
// Theme dependents do not rebuild and MaterialApp starts no theme
// animation when a host rebuilds for another reason.
@override
bool operator ==(Object other) =>
other is AppDesignTokens &&
other.design == design &&
other.radius == radius &&
other.flat == flat &&
other.frame == frame &&
other.panel == panel &&
other.ansi == ansi &&
other.promptGlyph == promptGlyph &&
other.transcript == transcript &&
other.composer == composer &&
other.selectedRow == selectedRow &&
other.reading == reading &&
other.chatColorSaturation == chatColorSaturation;
@override
int get hashCode => Object.hash(
design,
radius,
flat,
frame,
panel,
ansi,
promptGlyph,
transcript,
composer,
selectedRow,
reading,
chatColorSaturation,
);
/// Designs switch whole: a theme animation snaps halfway rather than
/// blending two designs' shapes.
@override
AppDesignTokens lerp(AppDesignTokens? other, double t) =>
other == null || t < 0.5 ? this : other;
}