This document outlines the comprehensive theming system used in the SparX Wallet Flutter application, including the design system, component library, and best practices for consistent UI development.
The SparX Wallet implements a sophisticated theming system with two versions:
- Legacy v1 theme system (deprecated, being phased out)
- Current v2 theme system (active, recommended for all new development)
The theme system is centralized in the packages/ui_components_lib/ directory as a separate package, providing a unified design system and component library.
The active theme system is now organized from the package root rather than a dedicated v2/ directory:
packages/ui_components_lib/lib/
├── colors.dart # Color palette definitions
├── constants.dart # Shared UI and theme constants
├── dimens.dart # Size and spacing design tokens
├── opac.dart # Opacity constants
├── predefined_theme.dart # Theme configurations
├── styles.dart # Shared style helpers
├── text_styles.dart # Typography system
├── theme_style.dart # Theme extension
├── ui_components_lib.dart # Main export file
├── components/ # High-level UI components
│ ├── button/
│ ├── common/
│ ├── displayable/
│ └── input/
├── widgets/ # Reusable themed widgets
├── extensions/ # Package extensions
├── fonts/ # Font configuration and assets
├── res/ # Packaged resources
└── utils/ # Shared utilities
The project uses Flutter's ThemeExtension pattern for custom theming:
class ThemeStyle extends ThemeExtension<ThemeStyle> {
ThemeStyle({
required this.colors,
required this.textStyles,
});
final ColorsPalette colors;
final TextStyles textStyles;
}The color system is organized into semantic groups for consistent usage through the ColorsPalette class:
Core Brand Colors:
primaryA,primaryB- Primary color variantsaccent- Accent color for highlightsnegative,warning,positive- State-specific colors
Background Colors:
background0throughbackground3- Hierarchical background levelsbackgroundInput,backgroundAccent- Specialized backgrounds- Alpha variants for transparency effects
Content Colors:
content0throughcontent4- Text hierarchy from primary to quinary- Used for different text importance levels
Border Colors:
border0throughborder2- Standard border hierarchyborderFocus,borderDisabled- State-specific borders
Colors are systematically defined in ColorsRes using a structured naming convention:
Color Categories:
- Primary colors (
p10-p100) - Brand purple tones - Neutral colors (
n10-n100) - Grayscale from dark to white - Error colors (
e10-e100) - Red/pink error states - Success colors (
s10-s100) - Green success states - Warning colors (
w10-w100) - Yellow/orange warning states
The numbering system (10-100) represents intensity levels, with higher numbers typically being lighter/more saturated.
The typography system provides semantic text styles through TextStyles with consistent hierarchy:
Display Styles (largest, for hero content):
displayLarge(52px),displayMedium(44px),displaySmall(36px)- Weight: 700 (bold)
Heading Styles (for section titles):
headingXXLarge(36px) throughheadingXSmall(14px)- Weight: 700 (bold)
- Six size variants for different heading levels
Label Styles (for UI labels and buttons):
labelLarge(18px) throughlabelXSmall(12px)- Weight: 500 (medium)
- Four size variants for interface elements
Paragraph Styles (for body text):
paragraphLarge(18px) throughparagraphXSmall(12px)- Weight: 400 (regular)
- Five size variants including
paragraphXMedium(17px)
All text styles use the Inter font family with:
- Responsive sizing using
.sppextension (screen-proportional pixels) - Calculated line heights (height = lineHeight / fontSize)
- Negative letter spacing for tighter text
- Theme-aware color application
DimensSize provides standardized spacing values:
- Available sizes:
d4,d8,d12,d16,d24,d32,d40,d48,d56,d64 - Usage: Padding, margins, and component sizing
- Scale: 4px increments for consistent spacing rhythm
DimensRadiusV2 defines corner radius standards:
- Available radii:
radius8,radius12,radius16,radius24,radius32 - Usage: Card corners, button borders, input fields
- Hierarchy: From subtle to pronounced rounding
DimensStrokeV2 provides border width standards:
- small (1px) - Default borders, dividers
- medium (2px) - Emphasized borders, focus states
Opac defines transparency levels:
- Available opacities:
opac10(0.1),opac16(0.16),opac50(0.5),opac80(0.8),opac100(1.0) - Usage: Overlays, disabled states, alpha backgrounds
The main app configures themes in /lib/app/view/app.dart using:
getPredefinedLightTheme()for light themegetPredefinedDarkTheme()for dark theme- Theme mode set to system preference
Note: Currently, both light and dark themes use identical color definitions (dark color scheme). The app is designed as a dark-themed application without true light mode support. Both theme functions return the same dark color palette.
@override
Widget build(BuildContext context) {
final theme = context.themeStyle; // Get theme extension
final colors = theme.colors; // Access color palette
final textStyles = theme.textStyles; // Access typography
return Container(
color: colors.background2,
padding: EdgeInsets.all(DimensSize.d16),
child: Text(
'Hello World',
style: textStyles.headingMedium.copyWith(
color: colors.content0,
),
),
);
}Use PrimaryText for semantic text with automatic theming:
- Available types:
displayLarge,headingLarge,labelMedium,paragraphSmall, etc. - Automatically applies theme colors and typography
- Supports text alignment and styling properties
Available themed button variants:
PrimaryButton- Main call-to-action buttonsAccentButton- Secondary actionsGhostButton- Tertiary actionsDestructiveButton- Delete/destructive actions- All support shape variants, icons, and automatic theme styling
Pre-built container components:
PrimaryCard- Standard card component with theme stylingShapedContainerColumn/Row- Layout containers with automatic theming- Support for spacing, padding, and color customization
Apply transparency using opacity utilities:
- Use
colors.content0.withAlpha(Opac.opac50.toByteInt())for custom transparency - Use pre-defined alpha colors like
backgroundAlpha,backgroundButtonAlpha - Combine with design tokens for consistent transparency levels
Buttons: Primary, Accent, Ghost, Float, Destructive, Transparent variants with automatic theme styling
Text Components: PrimaryText with all typography hierarchy levels and semantic styling
Cards and Containers: PrimaryCard, ShapedContainerColumn/Row, and specialized layout containers
Input Components: Text fields, dropdowns, checkboxes, switches with consistent theme integration
Overlays and Navigation: Bottom sheets, toasts, snackbars, modal dialogs with theme styling