Skip to main content
Chromia UI provides a powerful and flexible theming system that allows you to customize the look and feel of your application. The system is built around semantic design tokens and supports light/dark modes, custom themes, and multi-brand configurations.

Core Concepts

The theming system is composed of several key components:

ChromiaTheme

The root widget that propagates theme data down the widget tree

ChromiaThemeData

Contains all theme configuration including colors, typography, spacing, radius, and shadows

Design Tokens

Low-level design primitives that form the foundation of the theme

Brand Config

Brand-specific configuration for multi-brand applications

ChromiaTheme Widget

The ChromiaTheme widget is an InheritedWidget that makes theme data available throughout your widget tree.

Basic Usage

import 'package:chromia_ui/chromia_ui.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChromiaTheme(
      data: ChromiaThemeData.light(),
      child: MaterialApp(
        home: MyHomePage(),
      ),
    );
  }
}

Constructor

ChromiaTheme({
  required ChromiaThemeData data,
  required Widget child,
  Key? key,
})
data
ChromiaThemeData
required
The theme data to propagate down the widget tree
child
Widget
required
The widget below this widget in the tree

Static Methods

ChromiaTheme.of
ChromiaThemeData
Returns the ChromiaThemeData from the closest ChromiaTheme ancestor. If there is no ancestor, returns a default light theme.
final theme = ChromiaTheme.of(context);
final primaryColor = theme.colors.primary;
ChromiaTheme.maybeOf
ChromiaThemeData?
Returns the ChromiaThemeData from the closest ChromiaTheme ancestor, or null if there is no ancestor.
final theme = ChromiaTheme.maybeOf(context);
if (theme != null) {
  // Use theme
}

ChromiaThemeData

The ChromiaThemeData class combines all theme systems into a single cohesive configuration.

Properties

colors
ChromiaColors
The color scheme for the theme
typography
ChromiaTypography
The typography system with predefined text styles
spacing
ChromiaSpacing
The spacing system for consistent padding, margins, and gaps
radius
ChromiaRadius
The border radius system for consistent corner rounding
shadows
ChromiaShadows
The shadow system for creating depth and elevation
brandConfig
BrandConfig?
Optional brand configuration for multi-brand support
brightness
Brightness
Theme brightness (light or dark)

Factory Constructors

final theme = ChromiaThemeData.light();

Methods

copyWith
ChromiaThemeData
Creates a copy of this theme with the given fields replaced.
final customTheme = theme.copyWith(
  colors: customColors,
  spacing: customSpacing,
);
toMaterialTheme
ThemeData
Converts this ChromiaThemeData to a Material ThemeData for use with Flutter’s Material widgets.
MaterialApp(
  theme: chromiaTheme.toMaterialTheme(),
  home: MyHomePage(),
)
isDark
bool
Returns true if this is a dark theme
isLight
bool
Returns true if this is a light theme

Context Extensions

Chromia UI provides convenient BuildContext extensions for easy access to theme data:
import 'package:chromia_ui/chromia_ui.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Access the entire theme
    final theme = context.chromiaTheme;
    
    // Or access specific subsystems directly
    final colors = context.chromiaColors;
    final typography = context.chromiaTypography;
    final spacing = context.chromiaSpacing;
    final radius = context.chromiaRadius;
    final shadows = context.chromiaShadows;
    
    // Check theme brightness
    final isDark = context.isDarkTheme;
    final isLight = context.isLightTheme;
    
    return Container(
      color: colors.surface,
      padding: spacing.paddingL,
      child: Text(
        'Hello World',
        style: typography.bodyLarge.copyWith(
          color: colors.textPrimary,
        ),
      ),
    );
  }
}

Available Extensions

context.chromiaTheme
ChromiaThemeData
Returns the complete ChromiaThemeData
context.chromiaColors
ChromiaColors
Returns the ChromiaColors from the current theme
context.chromiaTypography
ChromiaTypography
Returns the ChromiaTypography from the current theme
context.chromiaSpacing
ChromiaSpacing
Returns the ChromiaSpacing from the current theme
context.chromiaRadius
ChromiaRadius
Returns the ChromiaRadius from the current theme
context.chromiaShadows
ChromiaShadows
Returns the ChromiaShadows from the current theme
context.isDarkTheme
bool
Returns true if the current theme is dark
context.isLightTheme
bool
Returns true if the current theme is light

Example: Complete Theme Setup

Here’s a complete example showing how to set up theming in your app:
import 'package:flutter/material.dart';
import 'package:chromia_ui/chromia_ui.dart';

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool isDarkMode = false;

  void toggleTheme() {
    setState(() {
      isDarkMode = !isDarkMode;
    });
  }

  @override
  Widget build(BuildContext context) {
    final chromiaTheme = isDarkMode 
      ? ChromiaThemeData.dark() 
      : ChromiaThemeData.light();

    return ChromiaTheme(
      data: chromiaTheme,
      child: MaterialApp(
        title: 'My App',
        theme: chromiaTheme.toMaterialTheme(),
        home: MyHomePage(onToggleTheme: toggleTheme),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final VoidCallback onToggleTheme;

  const MyHomePage({required this.onToggleTheme});

  @override
  Widget build(BuildContext context) {
    final colors = context.chromiaColors;
    final typography = context.chromiaTypography;
    final spacing = context.chromiaSpacing;

    return Scaffold(
      backgroundColor: colors.background,
      appBar: AppBar(
        title: Text('My App'),
        actions: [
          IconButton(
            icon: Icon(context.isDarkTheme ? Icons.light_mode : Icons.dark_mode),
            onPressed: onToggleTheme,
          ),
        ],
      ),
      body: Padding(
        padding: spacing.paddingL,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              'Welcome to Chromia UI',
              style: typography.headlineMedium.copyWith(
                color: colors.textPrimary,
              ),
            ),
            spacing.gapVM,
            Text(
              'A powerful Flutter design system',
              style: typography.bodyLarge.copyWith(
                color: colors.textSecondary,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Next Steps

Light & Dark Themes

Learn how to implement light and dark themes

Custom Themes

Create your own custom themes

Multi-Brand

Configure multiple brands in one app

Design Tokens

Explore the available design tokens

Build docs developers (and LLMs) love