applyThemePreset method

LaunchStyle applyThemePreset(
  1. BuildContext context,
  2. LaunchThemePreset preset
)

Applies a LaunchThemePreset to the current style, overriding color-related properties.

Implementation

LaunchStyle applyThemePreset(BuildContext context, LaunchThemePreset preset) {
  final theme = Theme.of(context);
  Color? newBackgroundColor;
  Color? newTextColor;
  Color? newIconColor;
  Color? newBorderColor;

  switch (preset) {
    case LaunchThemePreset.primary:
      newBackgroundColor = theme.primaryColor;
      newTextColor = theme.primaryTextTheme.labelLarge?.color ?? Colors.white;
      newIconColor = theme.primaryIconTheme.color ?? Colors.white;
      newBorderColor = theme.primaryColor;
      break;
    case LaunchThemePreset.secondary:
      newBackgroundColor = theme.colorScheme.secondary;
      newTextColor = theme.colorScheme.onSecondary;
      newIconColor = theme.colorScheme.onSecondary;
      newBorderColor = theme.colorScheme.secondary;
      break;
    case LaunchThemePreset.accent:
      newBackgroundColor = theme.colorScheme.tertiary;
      newTextColor = theme.colorScheme.onTertiary;
      newIconColor = theme.colorScheme.onTertiary;
      newBorderColor = theme.colorScheme.tertiary;
      break;
    case LaunchThemePreset.neutral:
      newBackgroundColor = theme.disabledColor;
      newTextColor = theme.textTheme.bodyMedium?.color;
      newIconColor = theme.iconTheme.color;
      newBorderColor = theme.disabledColor;
      break;
    case LaunchThemePreset.destructive:
      newBackgroundColor = theme.colorScheme.error;
      newTextColor = theme.colorScheme.onError;
      newIconColor = theme.colorScheme.onError;
      newBorderColor = theme.colorScheme.error;
      break;
  }

  return copyWith(
    backgroundColor: newBackgroundColor,
    textColor: newTextColor,
    iconColor: newIconColor,
    borderColor: newBorderColor,
  );
}