Skip to content

Creating a UI Kit Theme Variant

What you'll learn

  • Generating a new theme variant (e.g., high contrast, sepia, corporate)
  • Extending from an existing base theme (light or dark)
  • Configuring color, shadow, and typography overrides
  • Switching themes at runtime

Prerequisites

Step 1: Generate a Theme Variant

bash
archipelago generate ui_kit_theme

You will be prompted for:

  • themeName — e.g., high_contrast, sepia, corporate
  • prefix — e.g., App, My (your UI Kit prefix)
  • appNameMyApp
  • baseThemelight or dark (which theme to extend)
  • hasColorOverridestrue to generate color override placeholders
  • hasShadowOverridestrue for shadow overrides
  • hasTypographyOverridestrue for typography overrides

Or use a config file:

json
{
  "themeName": "high_contrast",
  "prefix": "App",
  "appName": "MyApp",
  "baseTheme": "light",
  "hasColorOverrides": true,
  "hasShadowOverrides": false,
  "hasTypographyOverrides": true
}

Step 2: Understand the Generated Structure

ui_kit/
└── lib/src/
    └── themes/
        ├── light/                         # Existing base theme
        ├── dark/                          # Existing base theme
        └── high_contrast/                 # New variant
            ├── high_contrast_theme.dart   # Theme data
            ├── high_contrast_colors.dart  # Color overrides
            └── high_contrast_typography.dart # Typography overrides

Step 3: Customize Colors

Edit the generated color overrides to match your variant's design:

dart
// high_contrast_colors.dart
class HighContrastColors extends AppColors {
  @override
  Color get primary => const Color(0xFF000000);

  @override
  Color get onPrimary => const Color(0xFFFFFFFF);

  @override
  Color get background => const Color(0xFFFFFFFF);

  @override
  Color get onBackground => const Color(0xFF000000);

  // High contrast: stronger borders and outlines
  @override
  Color get outline => const Color(0xFF000000);
}

Step 4: Customize Typography (if enabled)

dart
// high_contrast_typography.dart
class HighContrastTypography extends AppTypography {
  @override
  TextStyle get bodyLarge => super.bodyLarge.copyWith(
    fontWeight: FontWeight.w600,  // Bolder text for readability
    letterSpacing: 0.5,
  );
}

Step 5: Register and Switch Themes

The theme variant is automatically registered. Switch at runtime:

dart
// Access available themes
final themes = AppThemeRegistry.availableThemes;
// ['light', 'dark', 'high_contrast']

// Switch theme
AppThemeRegistry.setTheme('high_contrast');

Common Customizations

CustomizationWhere to Change
Override specific colors*_colors.dart — override individual getters
Override shadowsEnable hasShadowOverrides, edit *_shadows.dart
Override typographyEnable hasTypographyOverrides, edit *_typography.dart
Add component-specific stylesExtend component style resolvers
Set default themeAppThemeRegistry initialization

Next Steps

Built by Banua Coder