Merge main (Paper design) into the design perf budget
Paper's theme joins the cached builder; AppDesignTokens and ReadingType compare every new token by value, and Paper's tab indicator and switch outline resolver are kept per colour so a rebuilt Paper theme equals the last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,20 +2,33 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'paper_theme.dart';
|
||||
import 'terminal_theme.dart';
|
||||
|
||||
/// Every theme a design has built, by design, brightness and interface font.
|
||||
/// ThemeData is immutable; a handful of fonts and two brightnesses per design
|
||||
/// keep this small.
|
||||
final Map<(AppDesign, Brightness, String?), ThemeData> _themes = {};
|
||||
|
||||
/// An app-wide design: how every surface is shaped, typed and coloured, not
|
||||
/// only a colour. Each design builds a light and a dark [ThemeData] carrying
|
||||
/// its [AppDesignTokens], so widgets that draw design-specific shapes read the
|
||||
/// tokens instead of hard-coding one look.
|
||||
///
|
||||
/// Adding a design means one more value here and its theme builder; the
|
||||
/// Settings picker lists [AppDesign.values].
|
||||
/// Every theme a design has built, by design, brightness and interface font.
|
||||
/// ThemeData is immutable; a handful of fonts and two brightnesses per design
|
||||
/// keep this small.
|
||||
final Map<(AppDesign, Brightness, String?), ThemeData> _themes = {};
|
||||
|
||||
/// Adding a design:
|
||||
/// 1. add a value here with a stable [id], a [label] and a one-line
|
||||
/// [description] (the Settings picker lists [AppDesign.values]);
|
||||
/// 2. write its theme builder (`<name>_theme.dart` beside this file, with a
|
||||
/// palette and, when it needs one, its own typography) and return it from
|
||||
/// [build] ([light] and [dark] cache it); keep the theme value-equal when
|
||||
/// rebuilt (no fresh `Decoration`s or extensions without `==`);
|
||||
/// 3. give the theme an [AppDesignTokens] extension: set only the tokens it
|
||||
/// changes (corners, flat surfaces, frame, panel fill, transcript,
|
||||
/// composer and selected-row styles, reading type); every token defaults
|
||||
/// to the Default look;
|
||||
/// 4. give it a [swatch] for the picker and say whether it [usesInterfaceFont].
|
||||
/// 5. run the design budget (app/tool/perf/README.md) and keep it passing.
|
||||
/// Widgets read the tokens, so most surfaces follow without per-widget code.
|
||||
enum AppDesign {
|
||||
/// The app's own Material look.
|
||||
standard('default', 'Default', 'The app’s Material look.'),
|
||||
@@ -26,6 +39,14 @@ enum AppDesign {
|
||||
'terminal',
|
||||
'Terminal',
|
||||
'Monospace, flat frames and prompt-style chat, like a CLI agent.',
|
||||
),
|
||||
|
||||
/// A calm reading look: a warm paper page, a serif for reading, ink
|
||||
/// colours, hairline rules and the chat set as a typeset page.
|
||||
paper(
|
||||
'paper',
|
||||
'Paper',
|
||||
'Warm paper, serif reading text and ink colours; calm for long reads.',
|
||||
);
|
||||
|
||||
const AppDesign(this.id, this.label, this.description);
|
||||
@@ -72,8 +93,69 @@ enum AppDesign {
|
||||
(standard, Brightness.light) => appLightTheme(fontFamily: fontFamily),
|
||||
(standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily),
|
||||
(terminal, _) => terminalTheme(brightness),
|
||||
(paper, _) => paperTheme(brightness, fontFamily: fontFamily),
|
||||
};
|
||||
|
||||
/// Whether the device's interface font applies under this design.
|
||||
bool get usesInterfaceFont => this == standard;
|
||||
/// Whether the device's interface font applies under this design (Paper
|
||||
/// keeps it for its interface text and sets reading text in its serif).
|
||||
bool get usesInterfaceFont => this != terminal;
|
||||
|
||||
/// The picker's preview: the design's page, ink and accent in [brightness],
|
||||
/// without building its theme.
|
||||
DesignSwatch swatch(Brightness brightness) {
|
||||
final dark = brightness == Brightness.dark;
|
||||
return switch (this) {
|
||||
standard =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
Color(0xFF141416),
|
||||
Color(0xFFE6E0E9),
|
||||
Color(0xFFCFBDFE),
|
||||
)
|
||||
: const DesignSwatch(
|
||||
Color(0xFFFDF7FF),
|
||||
Color(0xFF1D1B20),
|
||||
Color(0xFF65558F),
|
||||
),
|
||||
terminal =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
Color(0xFF0B0B0B),
|
||||
Color(0xFFD7D7D2),
|
||||
Color(0xFF8CC38F),
|
||||
)
|
||||
: const DesignSwatch(
|
||||
Color(0xFFF7F6F1),
|
||||
Color(0xFF1E1E1C),
|
||||
Color(0xFF2F7434),
|
||||
),
|
||||
paper =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
Color(0xFF1E1B17),
|
||||
Color(0xFFE9E1D3),
|
||||
Color(0xFF9DB4DC),
|
||||
)
|
||||
: const DesignSwatch(
|
||||
Color(0xFFF8F4EB),
|
||||
Color(0xFF221E19),
|
||||
Color(0xFF2C4F86),
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// A design's three defining colours, for the picker's small preview.
|
||||
@immutable
|
||||
class DesignSwatch {
|
||||
const DesignSwatch(this.page, this.ink, this.accent);
|
||||
|
||||
/// The page (scaffold) colour.
|
||||
final Color page;
|
||||
|
||||
/// The main text colour.
|
||||
final Color ink;
|
||||
|
||||
/// The accent (primary) colour.
|
||||
final Color accent;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
/// How the chat transcript draws a conversation. Each design picks one; the
|
||||
/// transcript widgets branch on it, never on the design itself.
|
||||
enum TranscriptStyle {
|
||||
/// The operator's turns as bubbles on the trailing side, the agent's
|
||||
/// answers on the page and its activity as a one-line button (Default).
|
||||
bubbles,
|
||||
|
||||
/// A CLI's prompt line, glyph-led tool lines and bracketed injected
|
||||
/// prompts, every turn starting at the same edge (Terminal).
|
||||
prompt,
|
||||
|
||||
/// A typeset page: the operator's turns as indented block quotes under a
|
||||
/// small-caps label, answers as prose, activity as a muted marginal note
|
||||
/// and injected prompts as italic editorial notes (Paper).
|
||||
manuscript,
|
||||
}
|
||||
|
||||
/// How the chat composer frames its writing area.
|
||||
enum ComposerStyle {
|
||||
/// A floating pill (frosted, or flat and framed under a flat design) in
|
||||
/// the design's corners, with a focus ring along its edge.
|
||||
pill,
|
||||
|
||||
/// An open writing area on the page with a rule beneath it that takes
|
||||
/// the accent while the field has focus.
|
||||
underline,
|
||||
}
|
||||
|
||||
/// How a list (AppListRow) marks the row that is open. Every style keeps
|
||||
/// the leading bar in the row's accent; they differ in the fill and frame.
|
||||
enum SelectedRowStyle {
|
||||
/// Material's tonal `secondaryContainer` fill (Default).
|
||||
tonal,
|
||||
|
||||
/// The accent washed over the page, stronger than a tinted row, inside a
|
||||
/// hairline frame in the accent (Terminal).
|
||||
framed,
|
||||
|
||||
/// The accent washed over the page, without a frame (Paper).
|
||||
washed,
|
||||
}
|
||||
|
||||
/// The typography of reading text: chat messages, markdown answers and
|
||||
/// documents. Interface text (navigation, buttons, chips, labels, metadata)
|
||||
/// keeps the theme's own text roles.
|
||||
@immutable
|
||||
class ReadingType {
|
||||
const ReadingType({
|
||||
this.family,
|
||||
this.height,
|
||||
this.measure,
|
||||
this.scale = 1,
|
||||
this.figureWidth = 0.5,
|
||||
});
|
||||
|
||||
/// The reading face; null keeps the theme's body face.
|
||||
final String? family;
|
||||
|
||||
/// The line height as a multiple of the font size; null keeps the role's.
|
||||
final double? height;
|
||||
|
||||
/// The widest reading column in `ch` (widths of the digit zero in the
|
||||
/// reading face); null keeps the app's fixed reading width.
|
||||
final double? measure;
|
||||
|
||||
/// The reading size relative to the theme's `bodyLarge`.
|
||||
final double scale;
|
||||
|
||||
/// The width of the reading face's digit zero, in ems: what one `ch` of
|
||||
/// [measure] is worth (half an em for Source Serif's figures).
|
||||
final double figureWidth;
|
||||
|
||||
/// [base] in the reading face, size and line height.
|
||||
TextStyle? apply(TextStyle? base) {
|
||||
if (base == null) return null;
|
||||
if (family == null && height == null && scale == 1) return base;
|
||||
final size = base.fontSize;
|
||||
return base.copyWith(
|
||||
fontFamily: family,
|
||||
// The interface face stays as the fallback, so a glyph the reading
|
||||
// face lacks still draws from a bundled family.
|
||||
fontFamilyFallback: family == null || base.fontFamily == null
|
||||
? null
|
||||
: <String>[base.fontFamily!, ...?base.fontFamilyFallback],
|
||||
fontSize: size == null ? null : size * scale,
|
||||
height: height,
|
||||
letterSpacing: family == null ? null : 0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is ReadingType &&
|
||||
other.family == family &&
|
||||
other.height == height &&
|
||||
other.measure == measure &&
|
||||
other.scale == scale &&
|
||||
other.figureWidth == figureWidth;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(family, height, measure, scale, figureWidth);
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
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
|
||||
/// Default design leaves them to its colour scheme; Terminal sets them.
|
||||
/// Default design leaves them to its colour scheme; Terminal sets them, and
|
||||
/// Paper sets ink-toned ones.
|
||||
@immutable
|
||||
class AnsiAccents {
|
||||
const AnsiAccents({
|
||||
@@ -37,9 +41,15 @@ class AnsiAccents {
|
||||
}
|
||||
|
||||
/// The design-specific facts widgets read instead of hard-coding one look:
|
||||
/// corner shapes, whether surfaces are flat, frame colour and how the chat
|
||||
/// transcript is drawn. Every theme an [AppDesign] builds carries one; a
|
||||
/// theme without one (a test's bare `ThemeData`) reads as [standard].
|
||||
/// 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 Default 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({
|
||||
@@ -47,8 +57,14 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
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 Default design: every widget keeps its own shapes.
|
||||
@@ -59,7 +75,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
final AppDesign design;
|
||||
|
||||
/// The corner radius of framed surfaces (cards, pills, the composer,
|
||||
/// bubbles); null keeps each widget's own shape.
|
||||
/// bubbles, thumbnails, badges); null keeps each widget's own shape.
|
||||
final double? radius;
|
||||
|
||||
/// Whether surfaces are flat: no frosted glass, blur, highlight or shadow.
|
||||
@@ -68,6 +84,10 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// 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;
|
||||
@@ -75,8 +95,24 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// 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 => design == AppDesign.terminal;
|
||||
bool get terminal => transcript == TranscriptStyle.prompt;
|
||||
|
||||
/// The tokens of the theme at [context]; [standard] when it has none.
|
||||
static AppDesignTokens of(BuildContext context) =>
|
||||
@@ -96,21 +132,43 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
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
|
||||
@@ -123,12 +181,30 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
other.radius == radius &&
|
||||
other.flat == flat &&
|
||||
other.frame == frame &&
|
||||
other.panel == panel &&
|
||||
other.ansi == ansi &&
|
||||
other.promptGlyph == promptGlyph;
|
||||
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, ansi, promptGlyph);
|
||||
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.
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import '../text/terminal_symbols_font.dart';
|
||||
import 'app_font.dart';
|
||||
import 'paper_fonts.dart';
|
||||
|
||||
bool _registered = false;
|
||||
|
||||
/// Adds each bundled interface font's SIL Open Font License, and the
|
||||
/// Adds each bundled interface font's SIL Open Font License, Paper's reading
|
||||
/// serif's, and the
|
||||
/// terminal symbols font's MIT licence, to the
|
||||
/// [LicenseRegistry]. The texts are read from the bundle only when a licence
|
||||
/// page asks for them.
|
||||
@@ -21,6 +23,9 @@ void registerAppFontLicenses() {
|
||||
font.label,
|
||||
], await rootBundle.loadString(asset));
|
||||
}
|
||||
yield LicenseEntryWithLineBreaks(<String>[
|
||||
paperSerifFamily,
|
||||
], await rootBundle.loadString(paperSerifLicenseAsset));
|
||||
yield LicenseEntryWithLineBreaks(<String>[
|
||||
'Symbols Nerd Font Mono',
|
||||
], await rootBundle.loadString(terminalSymbolsLicenseAsset));
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'paper_theme.dart';
|
||||
|
||||
const Color _clear = Color(0x00000000);
|
||||
|
||||
// Kept per colour: a tab indicator and a resolver compare by identity, so
|
||||
// fresh ones would make a rebuilt theme unequal to the last
|
||||
// (test/perf/design_bench_test.dart).
|
||||
final Map<Color, Decoration> _tabIndicators = {};
|
||||
final Map<(Color, Color), WidgetStateProperty<Color?>> _trackOutlines = {};
|
||||
|
||||
/// [base] with Paper's controls: buttons, menus, chips, fields, search bars,
|
||||
/// tabs, segmented buttons, switches, checkboxes, sliders, badges and
|
||||
/// progress, all in [paperRadius] corners with hairline outlines, no
|
||||
/// elevation and the ink-blue accent.
|
||||
ThemeData paperControls(ThemeData base, PaperSurfaces surfaces) {
|
||||
final scheme = base.colorScheme;
|
||||
const rounded = PaperSurfaces.rounded;
|
||||
ButtonStyle buttons(ButtonStyle? style) =>
|
||||
(style ?? const ButtonStyle()).copyWith(
|
||||
shape: const WidgetStatePropertyAll(rounded),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shadowColor: const WidgetStatePropertyAll(_clear),
|
||||
);
|
||||
final outline = WidgetStatePropertyAll(BorderSide(color: scheme.outline));
|
||||
final menu = MenuStyle(
|
||||
backgroundColor: WidgetStatePropertyAll(surfaces.floating),
|
||||
elevation: const WidgetStatePropertyAll(PaperSurfaces.floatElevation),
|
||||
shadowColor: WidgetStatePropertyAll(surfaces.shadow),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
||||
shape: WidgetStatePropertyAll(surfaces.framed),
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)),
|
||||
);
|
||||
return base.copyWith(
|
||||
menuTheme: MenuThemeData(style: menu),
|
||||
dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu),
|
||||
menuButtonTheme: MenuButtonThemeData(
|
||||
style: MenuItemButton.styleFrom(shape: rounded),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
style: buttons(base.filledButtonTheme.style),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: buttons(base.elevatedButtonTheme.style).copyWith(
|
||||
backgroundColor: WidgetStatePropertyAll(scheme.surface),
|
||||
side: outline,
|
||||
),
|
||||
),
|
||||
outlinedButtonTheme: OutlinedButtonThemeData(
|
||||
style: buttons(base.outlinedButtonTheme.style).copyWith(side: outline),
|
||||
),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: buttons(base.textButtonTheme.style),
|
||||
),
|
||||
iconButtonTheme: IconButtonThemeData(
|
||||
style: buttons(base.iconButtonTheme.style),
|
||||
),
|
||||
segmentedButtonTheme: SegmentedButtonThemeData(
|
||||
style: buttons(base.segmentedButtonTheme.style).copyWith(
|
||||
side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)),
|
||||
),
|
||||
),
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
elevation: 0,
|
||||
focusElevation: 0,
|
||||
hoverElevation: 0,
|
||||
highlightElevation: 0,
|
||||
backgroundColor: scheme.surface,
|
||||
foregroundColor: scheme.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: PaperSurfaces.corners,
|
||||
side: BorderSide(color: scheme.outline),
|
||||
),
|
||||
),
|
||||
chipTheme: ChipThemeData(
|
||||
backgroundColor: _clear,
|
||||
selectedColor: scheme.secondaryContainer,
|
||||
shape: surfaces.framed,
|
||||
side: surfaces.hairline,
|
||||
elevation: 0,
|
||||
pressElevation: 0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
),
|
||||
// Only the base border: a field that sets `InputBorder.none` (the
|
||||
// composer, whose rule it draws itself) keeps none in every state.
|
||||
// An underline is a writing line on the page, not a box.
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
border: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: scheme.outline),
|
||||
),
|
||||
),
|
||||
searchBarTheme: SearchBarThemeData(
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
shape: const WidgetStatePropertyAll(rounded),
|
||||
side: WidgetStatePropertyAll(surfaces.hairline),
|
||||
backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLowest),
|
||||
surfaceTintColor: const WidgetStatePropertyAll(_clear),
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
),
|
||||
listTileTheme: const ListTileThemeData(shape: rounded),
|
||||
expansionTileTheme: const ExpansionTileThemeData(
|
||||
shape: Border(),
|
||||
collapsedShape: Border(),
|
||||
),
|
||||
tabBarTheme: TabBarThemeData(
|
||||
dividerColor: scheme.outlineVariant,
|
||||
labelColor: scheme.onSurface,
|
||||
unselectedLabelColor: scheme.onSurfaceVariant,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
indicator: _tabIndicators[scheme.primary] ??= UnderlineTabIndicator(
|
||||
borderSide: BorderSide(color: scheme.primary, width: 2),
|
||||
),
|
||||
),
|
||||
switchTheme: SwitchThemeData(
|
||||
trackOutlineColor: _trackOutlines[(scheme.primary, scheme.outline)] ??=
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) => states.contains(WidgetState.selected)
|
||||
? scheme.primary
|
||||
: scheme.outline,
|
||||
),
|
||||
trackOutlineWidth: const WidgetStatePropertyAll(1),
|
||||
),
|
||||
checkboxTheme: CheckboxThemeData(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(3)),
|
||||
),
|
||||
side: WidgetStateBorderSide.resolveWith(
|
||||
(states) => states.contains(WidgetState.selected)
|
||||
? BorderSide(color: scheme.primary, width: 1.5)
|
||||
: BorderSide(color: scheme.outline, width: 1.5),
|
||||
),
|
||||
),
|
||||
// A thin rule with a small round thumb, like a reading-app slider.
|
||||
sliderTheme: SliderThemeData(
|
||||
trackHeight: 2,
|
||||
activeTrackColor: scheme.primary,
|
||||
inactiveTrackColor: scheme.outlineVariant,
|
||||
thumbColor: scheme.primary,
|
||||
overlayColor: scheme.primary.withValues(alpha: 0.1),
|
||||
thumbShape: const RoundSliderThumbShape(
|
||||
enabledThumbRadius: 7,
|
||||
elevation: 0,
|
||||
pressedElevation: 0,
|
||||
),
|
||||
overlayShape: const RoundSliderOverlayShape(overlayRadius: 16),
|
||||
trackShape: const RoundedRectSliderTrackShape(),
|
||||
tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 1.5),
|
||||
activeTickMarkColor: scheme.onPrimary,
|
||||
inactiveTickMarkColor: scheme.outline,
|
||||
valueIndicatorColor: scheme.inverseSurface,
|
||||
valueIndicatorTextStyle: TextStyle(color: scheme.onInverseSurface),
|
||||
),
|
||||
// Counts in the accent's ink rather than an alarm red.
|
||||
badgeTheme: BadgeThemeData(
|
||||
backgroundColor: scheme.primary,
|
||||
textColor: scheme.onPrimary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
),
|
||||
progressIndicatorTheme: ProgressIndicatorThemeData(
|
||||
color: scheme.primary,
|
||||
linearTrackColor: scheme.outlineVariant,
|
||||
circularTrackColor: _clear,
|
||||
linearMinHeight: 2,
|
||||
),
|
||||
scrollbarTheme: const ScrollbarThemeData(
|
||||
radius: Radius.circular(4),
|
||||
thickness: WidgetStatePropertyAll(6),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Paper's reading serif (fonts/README.md): Source Serif 4.
|
||||
const String paperSerifFamily = 'Source Serif 4';
|
||||
|
||||
const String _directory = 'fonts/source-serif-4';
|
||||
|
||||
/// The licence shipped beside the files, registered with the app's other
|
||||
/// font licences.
|
||||
const String paperSerifLicenseAsset = '$_directory/OFL.txt';
|
||||
|
||||
/// Every face of [paperSerifFamily]: regular, italic, semibold and semibold
|
||||
/// italic. The loader reads each file's own weight and style.
|
||||
const List<String> paperSerifAssets = <String>[
|
||||
'$_directory/SourceSerif4-Regular.ttf',
|
||||
'$_directory/SourceSerif4-It.ttf',
|
||||
'$_directory/SourceSerif4-Semibold.ttf',
|
||||
'$_directory/SourceSerif4-SemiboldIt.ttf',
|
||||
];
|
||||
|
||||
Future<void>? _loading;
|
||||
|
||||
/// Registers [paperSerifFamily] the first time Paper's theme is built. The
|
||||
/// files are plain assets, not a `fonts:` family, so the web build fetches
|
||||
/// them only for a device that chooses Paper. Once registered the engine
|
||||
/// reports a font change and text lays out again in the serif; until then
|
||||
/// it reads in the interface face (the reading style's fallback). A failed
|
||||
/// load is logged and the interface face stays.
|
||||
Future<void> ensurePaperFonts() => _loading ??= _load();
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final loader = FontLoader(paperSerifFamily);
|
||||
for (final asset in paperSerifAssets) {
|
||||
loader.addFont(rootBundle.load(asset));
|
||||
}
|
||||
await loader.load();
|
||||
} catch (error) {
|
||||
debugPrint('Paper serif font did not load: $error');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
|
||||
/// Paper's status accents on its warm page: the usual hues pulled towards
|
||||
/// ink, so a status still reads by colour without shouting.
|
||||
const AnsiAccents paperLightAccents = AnsiAccents(
|
||||
green: Color(0xFF3D6B3F),
|
||||
cyan: Color(0xFF2E6670),
|
||||
yellow: Color(0xFF8A6A1F),
|
||||
red: Color(0xFF9B3B32),
|
||||
magenta: Color(0xFF7A4570),
|
||||
blue: Color(0xFF2C4F86),
|
||||
);
|
||||
|
||||
/// Paper's status accents on its night page.
|
||||
const AnsiAccents paperDarkAccents = AnsiAccents(
|
||||
green: Color(0xFF9DBE95),
|
||||
cyan: Color(0xFF8DB8BE),
|
||||
yellow: Color(0xFFD5B977),
|
||||
red: Color(0xFFDE9A8E),
|
||||
magenta: Color(0xFFC6A0C0),
|
||||
blue: Color(0xFF9DB4DC),
|
||||
);
|
||||
|
||||
/// Paper's colour scheme: a warm off-white page (or a sepia-tinted charcoal
|
||||
/// "night paper"), near-black ink with a muted secondary ink, surfaces that
|
||||
/// step only slightly from the page, hairline rules, and one restrained
|
||||
/// accent, a deep ink blue. Secondary and tertiary roles are quiet sepia
|
||||
/// tones, so nothing but the accent carries colour.
|
||||
ColorScheme paperColorScheme(Brightness brightness) {
|
||||
if (brightness == Brightness.dark) {
|
||||
return const ColorScheme(
|
||||
brightness: Brightness.dark,
|
||||
primary: Color(0xFF9DB4DC),
|
||||
onPrimary: Color(0xFF13213A),
|
||||
primaryContainer: Color(0xFF2B3447),
|
||||
onPrimaryContainer: Color(0xFFD7E1F2),
|
||||
secondary: Color(0xFFC2B6A2),
|
||||
onSecondary: Color(0xFF2A241C),
|
||||
secondaryContainer: Color(0xFF3A342B),
|
||||
onSecondaryContainer: Color(0xFFEAE1D1),
|
||||
tertiary: Color(0xFFD5B977),
|
||||
onTertiary: Color(0xFF2E2410),
|
||||
tertiaryContainer: Color(0xFF433824),
|
||||
onTertiaryContainer: Color(0xFFF0E1BC),
|
||||
error: Color(0xFFE39C90),
|
||||
onError: Color(0xFF3A120D),
|
||||
errorContainer: Color(0xFF4D2620),
|
||||
onErrorContainer: Color(0xFFF6D3CC),
|
||||
surface: Color(0xFF1E1B17),
|
||||
onSurface: Color(0xFFE9E1D3),
|
||||
onSurfaceVariant: Color(0xFFADA393),
|
||||
surfaceDim: Color(0xFF1A1814),
|
||||
surfaceBright: Color(0xFF3B362F),
|
||||
surfaceContainerLowest: Color(0xFF181612),
|
||||
surfaceContainerLow: Color(0xFF221F1A),
|
||||
surfaceContainer: Color(0xFF27231E),
|
||||
surfaceContainerHigh: Color(0xFF2D2923),
|
||||
surfaceContainerHighest: Color(0xFF35302A),
|
||||
outline: Color(0xFF746B5E),
|
||||
outlineVariant: Color(0xFF3D3830),
|
||||
shadow: Color(0xFF000000),
|
||||
scrim: Color(0xFF000000),
|
||||
inverseSurface: Color(0xFFE9E1D3),
|
||||
onInverseSurface: Color(0xFF26221D),
|
||||
inversePrimary: Color(0xFF2C4F86),
|
||||
surfaceTint: Color(0x00000000),
|
||||
);
|
||||
}
|
||||
return const ColorScheme(
|
||||
brightness: Brightness.light,
|
||||
primary: Color(0xFF2C4F86),
|
||||
onPrimary: Color(0xFFFFFFFF),
|
||||
primaryContainer: Color(0xFFDDE4EF),
|
||||
onPrimaryContainer: Color(0xFF132A4D),
|
||||
secondary: Color(0xFF6B5E4B),
|
||||
onSecondary: Color(0xFFFFFFFF),
|
||||
secondaryContainer: Color(0xFFEAE2D2),
|
||||
onSecondaryContainer: Color(0xFF2E271C),
|
||||
tertiary: Color(0xFF8A6A1F),
|
||||
onTertiary: Color(0xFFFFFFFF),
|
||||
tertiaryContainer: Color(0xFFF1E6C9),
|
||||
onTertiaryContainer: Color(0xFF3A2C08),
|
||||
error: Color(0xFF9B3B32),
|
||||
onError: Color(0xFFFFFFFF),
|
||||
errorContainer: Color(0xFFF4DCD6),
|
||||
onErrorContainer: Color(0xFF451410),
|
||||
surface: Color(0xFFF8F4EB),
|
||||
onSurface: Color(0xFF221E19),
|
||||
onSurfaceVariant: Color(0xFF655D51),
|
||||
surfaceDim: Color(0xFFE7E0D3),
|
||||
surfaceBright: Color(0xFFFCFAF5),
|
||||
surfaceContainerLowest: Color(0xFFFCFAF5),
|
||||
surfaceContainerLow: Color(0xFFF3EEE3),
|
||||
surfaceContainer: Color(0xFFEEE8DC),
|
||||
surfaceContainerHigh: Color(0xFFE9E2D5),
|
||||
surfaceContainerHighest: Color(0xFFE3DBCC),
|
||||
outline: Color(0xFFA09686),
|
||||
outlineVariant: Color(0xFFDDD5C6),
|
||||
shadow: Color(0xFF3B2F1E),
|
||||
scrim: Color(0xFF000000),
|
||||
inverseSurface: Color(0xFF2E2A24),
|
||||
onInverseSurface: Color(0xFFF3EEE3),
|
||||
inversePrimary: Color(0xFF9DB4DC),
|
||||
surfaceTint: Color(0x00000000),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design.dart';
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'paper_controls.dart';
|
||||
import 'paper_fonts.dart';
|
||||
import 'paper_palette.dart';
|
||||
import 'paper_typography.dart';
|
||||
|
||||
/// Paper's corner radius: every card, field, menu, dialog, chip, button and
|
||||
/// thumbnail takes it, so the page has one soft corner throughout.
|
||||
const double paperRadius = 8;
|
||||
|
||||
/// Paper's surfaces: hairline rules on the page rather than filled panels,
|
||||
/// and no elevation except a whisper of shadow under the pieces that float
|
||||
/// over the page (menus, dialogs, sheets, snack bars).
|
||||
class PaperSurfaces {
|
||||
PaperSurfaces(this.scheme);
|
||||
|
||||
final ColorScheme scheme;
|
||||
|
||||
static const BorderRadius corners = BorderRadius.all(
|
||||
Radius.circular(paperRadius),
|
||||
);
|
||||
|
||||
/// The whisper: a low elevation in the page's warm shadow at low alpha.
|
||||
static const double floatElevation = 3;
|
||||
|
||||
Color get shadow => scheme.shadow.withValues(
|
||||
alpha: scheme.brightness == Brightness.dark ? 0.5 : 0.22,
|
||||
);
|
||||
|
||||
BorderSide get hairline => BorderSide(color: scheme.outlineVariant);
|
||||
|
||||
/// A floating piece's fill: the brightest paper, so it lifts off the page
|
||||
/// by tone and hairline rather than by shadow.
|
||||
Color get floating => scheme.brightness == Brightness.dark
|
||||
? scheme.surfaceContainerHigh
|
||||
: scheme.surfaceContainerLowest;
|
||||
|
||||
RoundedRectangleBorder get framed =>
|
||||
RoundedRectangleBorder(borderRadius: corners, side: hairline);
|
||||
|
||||
static const RoundedRectangleBorder rounded = RoundedRectangleBorder(
|
||||
borderRadius: corners,
|
||||
);
|
||||
}
|
||||
|
||||
/// The Paper design's theme: a warm paper page (or night paper in dark), ink
|
||||
/// text with a muted secondary ink and one deep-blue accent, titles and
|
||||
/// reading text in a bundled serif with the interface font for chrome, soft
|
||||
/// [paperRadius] corners, hairline rules and almost no elevation. Building it
|
||||
/// starts loading the serif ([ensurePaperFonts]).
|
||||
ThemeData paperTheme(Brightness brightness, {String? fontFamily}) {
|
||||
unawaited(ensurePaperFonts());
|
||||
final scheme = paperColorScheme(brightness);
|
||||
final surfaces = PaperSurfaces(scheme);
|
||||
final base = ThemeData(
|
||||
platform: kIsWeb ? TargetPlatform.android : null,
|
||||
colorScheme: scheme,
|
||||
fontFamily: fontFamily,
|
||||
scaffoldBackgroundColor: scheme.surface,
|
||||
canvasColor: scheme.surface,
|
||||
pageTransitionsTheme: appPageTransitions,
|
||||
dividerColor: scheme.outlineVariant,
|
||||
shadowColor: surfaces.shadow,
|
||||
extensions: [
|
||||
AppDesignTokens(
|
||||
design: AppDesign.paper,
|
||||
radius: paperRadius,
|
||||
flat: true,
|
||||
frame: scheme.outlineVariant,
|
||||
panel: scheme.surface,
|
||||
ansi: brightness == Brightness.dark
|
||||
? paperDarkAccents
|
||||
: paperLightAccents,
|
||||
transcript: TranscriptStyle.manuscript,
|
||||
composer: ComposerStyle.underline,
|
||||
selectedRow: SelectedRowStyle.washed,
|
||||
reading: paperReading,
|
||||
chatColorSaturation: 0.45,
|
||||
),
|
||||
],
|
||||
);
|
||||
final floating = surfaces.floating;
|
||||
final floatingShape = RoundedRectangleBorder(
|
||||
borderRadius: PaperSurfaces.corners,
|
||||
side: surfaces.hairline,
|
||||
);
|
||||
return paperControls(
|
||||
base.copyWith(
|
||||
textTheme: paperTextTheme(base.textTheme),
|
||||
primaryTextTheme: paperTextTheme(base.primaryTextTheme),
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: scheme.surface,
|
||||
foregroundColor: scheme.onSurface,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
shape: Border(bottom: surfaces.hairline),
|
||||
),
|
||||
// Only the hairline and the corners: each card variant keeps its own
|
||||
// fill, so a selected graph node still reads apart.
|
||||
cardTheme: CardThemeData(
|
||||
elevation: 0,
|
||||
shadowColor: const Color(0x00000000),
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
shape: surfaces.framed,
|
||||
),
|
||||
dialogTheme: DialogThemeData(
|
||||
backgroundColor: floating,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
elevation: PaperSurfaces.floatElevation,
|
||||
shadowColor: surfaces.shadow,
|
||||
shape: floatingShape,
|
||||
),
|
||||
bottomSheetTheme: BottomSheetThemeData(
|
||||
backgroundColor: floating,
|
||||
modalBackgroundColor: floating,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
elevation: PaperSurfaces.floatElevation,
|
||||
modalElevation: PaperSurfaces.floatElevation,
|
||||
shadowColor: surfaces.shadow,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(paperRadius),
|
||||
),
|
||||
),
|
||||
dragHandleColor: scheme.outline,
|
||||
),
|
||||
popupMenuTheme: PopupMenuThemeData(
|
||||
color: floating,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
elevation: PaperSurfaces.floatElevation,
|
||||
shadowColor: surfaces.shadow,
|
||||
shape: floatingShape,
|
||||
),
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
backgroundColor: scheme.inverseSurface,
|
||||
contentTextStyle: base.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onInverseSurface,
|
||||
),
|
||||
actionTextColor: scheme.inversePrimary,
|
||||
elevation: PaperSurfaces.floatElevation,
|
||||
shape: PaperSurfaces.rounded,
|
||||
),
|
||||
tooltipTheme: TooltipThemeData(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.inverseSurface.withValues(alpha: 0.94),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
textStyle: base.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
dividerTheme: DividerThemeData(
|
||||
color: scheme.outlineVariant,
|
||||
thickness: 1,
|
||||
space: 1,
|
||||
),
|
||||
navigationRailTheme: NavigationRailThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
elevation: 0,
|
||||
indicatorColor: scheme.secondaryContainer,
|
||||
indicatorShape: PaperSurfaces.rounded,
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
elevation: 0,
|
||||
indicatorColor: scheme.secondaryContainer,
|
||||
indicatorShape: PaperSurfaces.rounded,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
),
|
||||
drawerTheme: DrawerThemeData(
|
||||
backgroundColor: scheme.surface,
|
||||
surfaceTintColor: const Color(0x00000000),
|
||||
elevation: PaperSurfaces.floatElevation,
|
||||
shadowColor: surfaces.shadow,
|
||||
),
|
||||
textSelectionTheme: TextSelectionThemeData(
|
||||
cursorColor: scheme.primary,
|
||||
selectionColor: scheme.primary.withValues(alpha: 0.22),
|
||||
selectionHandleColor: scheme.primary,
|
||||
),
|
||||
),
|
||||
surfaces,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_styles.dart';
|
||||
import 'paper_fonts.dart';
|
||||
|
||||
/// Paper's reading type: the serif at a little over the body size, with a
|
||||
/// book's line height and a measure of about seventy characters.
|
||||
const ReadingType paperReading = ReadingType(
|
||||
family: paperSerifFamily,
|
||||
height: 1.55,
|
||||
measure: 70,
|
||||
scale: 17 / 16,
|
||||
);
|
||||
|
||||
/// [base] for Paper: the page's titles (display, headline and the large
|
||||
/// title role a page or dialog heads with) in the reading serif, semibold
|
||||
/// and without added tracking; every interface role (list titles, labels,
|
||||
/// buttons, chips, metadata and body text in controls) keeps the interface
|
||||
/// face, so chrome stays a clean sans.
|
||||
TextTheme paperTextTheme(TextTheme base) {
|
||||
TextStyle? serif(TextStyle? style) => style?.copyWith(
|
||||
fontFamily: paperSerifFamily,
|
||||
fontFamilyFallback: style.fontFamily == null
|
||||
? null
|
||||
: <String>[style.fontFamily!],
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
return base.copyWith(
|
||||
displayLarge: serif(base.displayLarge),
|
||||
displayMedium: serif(base.displayMedium),
|
||||
displaySmall: serif(base.displaySmall),
|
||||
headlineLarge: serif(base.headlineLarge),
|
||||
headlineMedium: serif(base.headlineMedium),
|
||||
headlineSmall: serif(base.headlineSmall),
|
||||
titleLarge: serif(base.titleLarge),
|
||||
);
|
||||
}
|
||||
@@ -49,6 +49,8 @@ ThemeData terminalTheme(Brightness brightness) {
|
||||
flat: true,
|
||||
frame: scheme.outlineVariant,
|
||||
ansi: ansi,
|
||||
transcript: TranscriptStyle.prompt,
|
||||
selectedRow: SelectedRowStyle.framed,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user