fluttercnfluttercn

Theming

A comprehensive theming system for your Flutter app with light and dark mode support.

Beta

This theming system is currently in beta and may change in future releases. Built with inspiration from shadcn/ui.

Overview

A complete design foundation for your Flutter app. Colors, typography, spacing, shadows—everything you need to build consistent, beautiful interfaces that work in both light and dark modes.

Installation

npx fluttercn@latest init

This creates lib/config/theme.dart with the complete theming system.

Setup

Wire up the theme in your app:

MaterialApp(
  theme: AppTheme.lightTheme,
  darkTheme: AppTheme.darkTheme,
  themeMode: ThemeMode.system, // Respects system preference
  home: HomeScreen(),
)
MaterialApp(
  theme: AppTheme.lightTheme,
  themeMode: ThemeMode.light,
  home: HomeScreen(),
)
MaterialApp(
  theme: AppTheme.darkTheme,
  themeMode: ThemeMode.dark,
  home: HomeScreen(),
)

Colors

Semantic Colors

Colors with meaning that adapt to light and dark themes:

ColorPurposeUsage
AppTheme.primaryBrand colorPrimary actions, focus states
AppTheme.secondarySupporting colorSecondary UI elements
AppTheme.successPositive feedbackSuccess states, confirmations
AppTheme.warningCautionWarnings, important notices
AppTheme.errorDestructive actionsErrors, validation failures
AppTheme.infoInformationalHelp text, info messages

Text Colors

Hierarchical text colors for visual structure:

ColorOpacityUsage
AppTheme.textPrimary100%Headings, primary content
AppTheme.textSecondary~70%Body text, descriptions
AppTheme.textTertiary~50%Captions, metadata
AppTheme.textDisabled~40%Disabled states

Surface Colors

Background and container colors:

ColorPurpose
AppTheme.backgroundPage backgrounds
AppTheme.surfaceCards, modals, elevated surfaces
AppTheme.surfaceVariantAlternative surface color
AppTheme.surfaceContainerNested containers

Border Colors

ColorUsage
AppTheme.borderStandard borders (1px)
AppTheme.borderLightSubtle separators
AppTheme.borderFocusFocus indicators

Gray Scale

11-step grayscale from 50 (lightest) to 950 (darkest):

AppTheme.gray50   // Almost white
AppTheme.gray100  // Very light gray
AppTheme.gray200  // Light gray
AppTheme.gray300  // Medium-light gray
AppTheme.gray400
AppTheme.gray500  // True middle gray
AppTheme.gray600
AppTheme.gray700  // Medium-dark gray
AppTheme.gray800  // Dark gray
AppTheme.gray900  // Very dark gray
AppTheme.gray950  // Almost black

Grayscale automatically inverts in dark mode—gray50 becomes darkest, gray950 becomes lightest.

Typography

Type Scale

A systematic scale for text hierarchy:

StyleSizeWeightLine HeightUse Case
Display Large32pxBold1.2Hero sections
Display Medium28pxBold1.2Page titles
Display Small24pxBold1.2Section headers
Headline Large20pxSemi-bold1.3Card headers
Headline Medium18pxSemi-bold1.3Subsections
Headline Small16pxSemi-bold1.4List headers
Title Large16pxMedium1.4Card titles
Title Medium14pxMedium1.4Item titles
Title Small12pxMedium1.4Labels
Body Large16pxRegular1.6Large body text
Body Medium14pxRegular1.6Standard body text
Body Small12pxRegular1.6Small body text
Label Large14pxMedium1.4Button text
Label Medium12pxMedium1.4Tags, badges
Label Small10pxMedium1.4Tiny labels
Text('Page Title', style: AppTheme.displayLarge)
Text('Body content here', style: AppTheme.bodyMedium)

Spacing

Space Scale

Consistent spacing creates visual rhythm:

TokenValueCommon Usage
spaceXs4pxTight spacing, icon gaps
spaceSm8pxSmall gaps between related items
spaceMd12pxDefault spacing
spaceLg16pxSection spacing
spaceXl20pxLarge gaps
space2xl24pxMajor section spacing
space3xl32pxPage-level spacing
space4xl40pxExtra large spacing

Padding Helpers

Pre-built padding for common patterns:

All Sides

Container(padding: AppTheme.paddingSm)   // 8px all sides
Container(padding: AppTheme.paddingMd)   // 12px all sides
Container(padding: AppTheme.paddingLg)   // 16px all sides

Horizontal Only

Container(padding: AppTheme.paddingHorizontalSm)   // 8px left/right
Container(padding: AppTheme.paddingHorizontalMd)   // 12px left/right
Container(padding: AppTheme.paddingHorizontalLg)   // 16px left/right

Vertical Only

Container(padding: AppTheme.paddingVerticalSm)   // 8px top/bottom
Container(padding: AppTheme.paddingVerticalMd)   // 12px top/bottom
Container(padding: AppTheme.paddingVerticalLg)   // 16px top/bottom

Gap Widgets

For spacing in Columns and Rows:

Column(
  children: [
    Widget1(),
    AppTheme.gapSm,      // 8px vertical gap
    Widget2(),
    AppTheme.gapMd,      // 12px vertical gap
    Widget3(),
  ],
)
 
Row(
  children: [
    Widget1(),
    AppTheme.gapHorizontalLg,  // 16px horizontal gap
    Widget2(),
  ],
)

Border Radius

Consistent corner radii for cohesive UI:

TokenRadiusVisual Effect
borderRadiusXs4pxSubtle rounding
borderRadiusSm6pxSmall components
borderRadiusMd8pxStandard rounding
borderRadiusLg12pxCards, buttons (default)
borderRadiusXl16pxLarge cards
borderRadius2xl20pxExtra rounded
borderRadius3xl24pxVery rounded
borderRadius4xl32pxExtremely rounded
borderRadiusFull9999pxPerfect circles/pills
Container(
  decoration: BoxDecoration(
    borderRadius: AppTheme.borderRadiusLg,  // 12px corners
  ),
)

Shadows

Elevation system for depth and hierarchy:

ShadowElevationUsage
shadowSm1dpSubtle lift (cards)
shadowMd2dpStandard elevation (buttons)
shadowLg4dpFloating elements (dialogs)
shadowXl8dpProminent elements (modals)
Container(
  decoration: BoxDecoration(
    boxShadow: AppTheme.shadowMd,
  ),
)

Shadows automatically adjust opacity for light and dark themes.

Motion

Duration

Animation timing for smooth transitions:

DurationTimeUsage
durationFast150msMicro-interactions, hovers
durationNormal300msStandard transitions
durationSlow500msComplex animations

Curves

Easing functions for natural motion:

CurveEffect
curveEaseInSlow start, fast end
curveEaseOutFast start, slow end
curveEaseInOutSmooth acceleration/deceleration
AnimatedContainer(
  duration: AppTheme.durationNormal,
  curve: AppTheme.curveEaseInOut,
)

Customization

Changing Colors

Edit lib/config/theme.dart to match your brand:

class CoreColors {
  static const Color primary = Color(0xFF000000);  // Your brand color
  static const Color success = Color(0xFF10B981);  // Your success color
  // ...
}

Light/Dark Variations

Customize theme-specific colors:

class LightColors {
  static const Color textPrimary = Color(0xFF171717);  // Light mode text
  // ...
}
 
class DarkColors {
  static const Color textPrimary = Color(0xFFFAFAFA);  // Dark mode text
  // ...
}

Only modify initializeTheme if building custom components that need theme access outside the widget tree. fluttercn components handle theme changes automatically.

Design Tokens

The theme provides a complete token system—every value has a semantic name. Use tokens instead of hardcoded values for:

  • Consistency - Same spacing everywhere
  • Maintainability - Change once, update everywhere
  • Theme Support - Automatic light/dark adaptation
  • Scalability - Easy to extend and modify
// ❌ Don't do this
Container(
  padding: EdgeInsets.all(16),
  decoration: BoxDecoration(
    color: Color(0xFFFFFFFF),
    borderRadius: BorderRadius.circular(12),
  ),
)
 
// ✅ Do this
Container(
  padding: AppTheme.paddingLg,
  decoration: BoxDecoration(
    color: AppTheme.surface,
    borderRadius: AppTheme.borderRadiusLg,
  ),
)