Menu

Theming and Design System

Relevant source files

This document provides detailed information about the theming architecture and design system implementation in the Flutter Mobile Project Template. It covers theme configuration, color schemes, component-specific themes, theme extensions, and the design system catalog application.

1. Theme Structure Overview

The template implements Material Design theming principles with support for light and dark themes. The theme system is organized in a modular fashion with separate components for color schemes, typography, and component-specific themes.

Sources:

2. Theme Configuration

The template provides factory functions for creating light and dark themes. These functions are the entry points for theme configuration.

2.1 Base Theme Configuration

The theme is created using the _createTheme function, which combines the color scheme, component themes, and theme extensions into a ThemeData object:

Sources:

2.2 Color Schemes

The template uses Material Design color schemes with predefined color palettes for light and dark themes. These color schemes are defined in color_schemes.dart:

Color RoleLight ThemeDark Theme
Primary#006496#90CDFF
Secondary#50606F#B8C8D9
Tertiary#66587B#D1BFE7
Error#BA1A1A#FFB4AB
Background#FCFCFF#1A1C1E

Sources:

2.3 Component-Specific Themes

The design system includes specific themes for various UI components:

2.3.1 AppBar Theme

The AppBarTheme is configured using the _createAppBarTheme function, which provides consistent styling for app bars across the application:

Sources:

2.3.2 Bottom Navigation Bar Theme

The bottom navigation bar is themed through the _createBottomNavigationBarTheme function:

Sources:

3. Theme Extensions

The template leverages Flutter's ThemeExtension mechanism to add custom theme properties that aren't covered by the standard Material theme.

3.1 AppColors Extension

The AppColors extension provides additional color definitions beyond the standard Material color scheme:

Sources:

4. Theme Usage

4.1 Accessing Theme Data in Widgets

Themes can be accessed throughout the application using Theme.of(context):

final theme = Theme.of(context);
final textStyle = theme.textTheme.headline6;
final primaryColor = theme.colorScheme.primary;

// For custom theme extensions
final appColors = theme.extension<AppColors>();
final iconColor = appColors?.icon;

4.2 Theme Extensions Usage

Custom theme extensions can be accessed using the extension<T>() method on ThemeData:

// Accessing the AppColors extension
final appColors = Theme.of(context).extension<AppColors>();
final iconColor = appColors?.icon;

Sources:

5. Design System Catalog

The template includes a catalog application that showcases all UI components with their respective themes.

5.1 Catalog Application Structure

The catalog app uses the Widgetbook library to organize and display UI components:


Sources:

5.2 Theme Preview Categories

The catalog app organizes theme previews into multiple categories:

  1. Actions - Buttons, FABs, Icon buttons, etc.
  2. Communication - Badges, Progress indicators, Snackbars
  3. Containment - Alert dialogs, Bottom sheets, Cards, Dividers
  4. Navigation - App bars, Navigation bars, Tabs
  5. Selection - Checkboxes, Chips, Date pickers, Menus
  6. Style - Color scheme, Typography
  7. Text Inputs - Text fields, etc.

Sources:

5.3 Color Scheme Preview

The catalog app includes detailed previews of all color scheme elements:

Sources:

5.4 Typography Preview

The catalog app showcases all typography styles defined in the theme:

Typography CategoryStyles
DisplayLarge, Medium, Small
HeadlineLarge, Medium, Small
TitleLarge, Medium, Small
BodyLarge, Medium, Small
LabelLarge, Medium, Small

Sources:

6. Theme Switching

The theme system supports dynamic theme switching between light and dark modes. This is typically implemented using Riverpod providers, but the implementation details are not shown in the provided files. For more details on theme switching implementation, see the Settings Feature documentation 4.1.

  • For information about UI components usage, see UI Components
  • For information about application initialization including theme setup, see App Initialization
  • For details on how theme selection is implemented in the settings, see Settings Feature
Syntax error in textmermaid version 11.6.0