courierThemeForBackground function

ThemeData courierThemeForBackground(
  1. ThemeData base,
  2. Color background
)

base with background as the surface color. When background is dark in a light theme, or light in a dark theme, the default foreground colors switch to white or black.

Implementation

ThemeData courierThemeForBackground(ThemeData base, Color background) {
  final brightness = ThemeData.estimateBrightnessForColor(background);

  final theme = base.copyWith(
    scaffoldBackgroundColor: background,
    canvasColor: background,
    bottomSheetTheme: base.bottomSheetTheme.copyWith(
      backgroundColor: background,
      modalBackgroundColor: background,
    ),
  );

  if (brightness == base.brightness) return theme;

  final foreground = brightness == Brightness.dark ? Colors.white : Colors.black;

  return theme.copyWith(
    // Resolve the accent before the brightness changes
    primaryColor: base.courierAccentColor,
    colorScheme: base.colorScheme.copyWith(
      brightness: brightness,
      surface: background,
      onSurface: foreground,
      onSurfaceVariant: foreground.withValues(alpha: 0.7),
      outline: foreground.withValues(alpha: 0.5),
      outlineVariant: foreground.withValues(alpha: 0.12),
    ),
    textTheme: base.textTheme.apply(bodyColor: foreground, displayColor: foreground),
    iconTheme: base.iconTheme.copyWith(color: foreground),
    dividerColor: foreground.withValues(alpha: 0.12),
  );
}