import 'package:flutter/material.dart'; import 'app_design_tokens.dart'; import 'app_theme.dart'; import 'compact_theme.dart'; import 'crt_palette.dart'; import 'crt_theme.dart'; import 'glass_theme.dart'; import 'high_contrast_theme.dart'; import 'notebook_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: /// 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 (`_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 Classic 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 original Material look. Its stored id stays `default` (the /// id it had when it was the default); the picker calls it Classic so it /// does not read as "whatever the app starts with". standard('default', 'Classic', 'The app’s original Material look.'), /// A terminal-style look: monospace text, near-black pages, thin frames /// and a transcript drawn as prompt and tool lines. terminal( '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.', ), /// The Classic look packed tight for a big monitor: smaller type, thin /// rows, 18px icons, an icon-only rail and modest corners. compact( 'compact', 'Compact', 'Classic’s Material look, dense: small type, thin rows, more on screen.', ), /// A notebook IDE look: the chat as numbered In/Out cells with tool calls /// as collapsible sub-cells, light grey cells and hairline borders. notebook( 'notebook', 'Notebook', '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( 'glass', 'Glass', 'Frosted panes over a soft gradient, rounded cards and gentle depth.', ), /// Terminal's structure on a monochrome tube: green phosphor shades, square /// frames, a faint glow and static scanlines; [retroCrtAmber] is the same /// design in amber. retroCrt( 'retro-crt', 'Retro CRT', 'Terminal on a green phosphor tube: one hue, glow and scanlines.', ), /// [retroCrt] in amber phosphor. retroCrtAmber( 'retro-crt-amber', 'Retro CRT (amber)', 'Terminal on an amber phosphor tube: one hue, glow and scanlines.', ); const AppDesign(this.id, this.label, this.description); /// The stored value; stable across releases and renames. final String id; /// The picker's name for the design. final String label; /// The picker's one-line summary of the design. final String description; /// The design a device has before it chooses one: Terminal. static const AppDesign defaultDesign = terminal; /// The design stored as [id], or [defaultDesign] for an unknown or missing /// id. A stored choice (Classic's `default` included) is kept. static AppDesign fromId(String? id) { for (final design in values) { if (design.id == id) return design; } return defaultDesign; } /// The design's light theme. [fontFamily] is the device's interface font; /// a design with its own family (Terminal's monospace) keeps that instead. /// Cached: the same object for the same design and font, so a host that /// rebuilds for another reason hands its subtree the same theme. ThemeData light({String? fontFamily}) => _cached(Brightness.light, fontFamily); /// The design's dark theme; see [light]. ThemeData dark({String? fontFamily}) => _cached(Brightness.dark, fontFamily); ThemeData _cached(Brightness brightness, String? fontFamily) { final family = usesInterfaceFont ? fontFamily : null; return _themes[(this, brightness, family)] ??= build( brightness, fontFamily: family, ); } /// 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), (highContrast, _) => highContrastTheme(brightness, fontFamily: fontFamily), (glass, _) => glassTheme(brightness, fontFamily: fontFamily), (retroCrt || retroCrtAmber, _) => crtTheme(crtPhosphor!, this, brightness), }; /// The phosphor of a Retro CRT design; null for every other design. CrtPhosphor? get crtPhosphor => switch (this) { retroCrt => CrtPhosphor.green, retroCrtAmber => CrtPhosphor.amber, _ => null, }; /// Whether this design packs the interface densely /// ([DesignDensity.dense]); its theme hosts switch to and from it without /// a blend ([AppDesignController.themeAnimationDuration]). bool get dense => light().extension()?.density.dense ?? false; /// 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 && crtPhosphor == null; /// 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 || compact => 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), ), notebook => dark ? const DesignSwatch( Color(0xFF17181A), Color(0xFFE4E5E7), Color(0xFF7FB0F0), ) : const DesignSwatch( Color(0xFFFFFFFF), 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( Color(0xFF101220), Color(0xFFE9E9F4), Color(0xFFB9B0FF), ) : const DesignSwatch( Color(0xFFF2F3FA), Color(0xFF1A1A2B), Color(0xFF5546C7), ), retroCrt || retroCrtAmber => () { final ramp = CrtRamp(crtPhosphor!, brightness); return DesignSwatch(ramp.page, ramp.text, ramp.accent); }(), }; } /// How many lines of ink the picker's preview draws: Compact's packs more /// into the same page. int get swatchLines => this == compact ? 4 : 2; } /// 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; }