adaptive static method
Adaptive theme that auto-switches based on terminal background.
This is the recommended default. Colors automatically adapt when the terminal reports its background color via OSC 11.
Uses AdaptiveColor for all color slots, which resolve based on hasDarkBackground at render time.
Implementation
static Theme adaptive() {
// Primary/accent colors - cyan for both, works well on light and dark
const primary = AdaptiveColor(
light: AnsiColor(33), // Blue
dark: AnsiColor(39), // Cyan
);
const secondary = AdaptiveColor(
light: AnsiColor(90), // Purple
dark: AnsiColor(99), // Purple
);
// Surface/background - these are the key adaptive colors
const surface = AdaptiveColor(
light: AnsiColor(254), // Light gray
dark: AnsiColor(236), // Dark gray
);
const background = AdaptiveColor(
light: AnsiColor(255), // White
dark: AnsiColor(233), // Very dark gray
);
// Status colors
const error = AdaptiveColor(
light: AnsiColor(160), // Dark red
dark: AnsiColor(196), // Bright red
);
const success = AdaptiveColor(
light: AnsiColor(28), // Dark green
dark: AnsiColor(42), // Bright green
);
const warning = AdaptiveColor(
light: AnsiColor(172), // Dark orange
dark: AnsiColor(214), // Bright orange
);
// Text colors - must contrast with background
const onPrimary = AdaptiveColor(
light: AnsiColor(255), // White on dark primary
dark: AnsiColor(232), // Black on light primary
);
const onSecondary = AnsiColor(255); // White
const onSurface = AdaptiveColor(
light: AnsiColor(235), // Dark gray on light surface
dark: AnsiColor(252), // Light gray on dark surface
);
const onBackground = AdaptiveColor(
light: AnsiColor(232), // Black on light background
dark: AnsiColor(250), // Light gray on dark background
);
const onError = AnsiColor(255); // White
const muted = AdaptiveColor(
light: AnsiColor(245), // Medium gray
dark: AnsiColor(242), // Medium gray
);
const border = AdaptiveColor(
light: AnsiColor(250), // Light gray border
dark: AnsiColor(238), // Dark gray border
);
return Theme(
primary: primary,
secondary: secondary,
surface: surface,
background: background,
error: error,
success: success,
warning: warning,
onPrimary: onPrimary,
onSecondary: onSecondary,
onSurface: onSurface,
onBackground: onBackground,
onError: onError,
muted: muted,
border: border,
// Extended colors
surfaceVariant: const AdaptiveColor(
light: AnsiColor(253),
dark: AnsiColor(234),
),
onSurfaceVariant: onSurface,
outline: const AdaptiveColor(light: AnsiColor(248), dark: AnsiColor(240)),
info: primary,
onSuccess: const AdaptiveColor(
light: AnsiColor(255),
dark: AnsiColor(232),
),
onWarning: const AdaptiveColor(
light: AnsiColor(232),
dark: AnsiColor(232),
),
onInfo: onPrimary,
highlight: const AdaptiveColor(
light: AnsiColor(153),
dark: AnsiColor(25),
),
onHighlight: const AdaptiveColor(
light: AnsiColor(232),
dark: AnsiColor(255),
),
shadow: const AdaptiveColor(light: AnsiColor(248), dark: AnsiColor(232)),
// Text styles
titleLarge: Style().bold().foreground(onBackground),
titleMedium: Style().bold().foreground(onSurface),
titleSmall: Style().bold().foreground(muted),
bodyLarge: Style().foreground(onBackground),
bodyMedium: Style().foreground(onSurface),
bodySmall: Style().foreground(muted),
labelLarge: Style().foreground(onSurface),
labelMedium: Style().foreground(muted),
labelSmall: Style().dim().foreground(muted),
);
}