Overview
Numix uses Flutter’s Material 3 design system to provide a modern, consistent user interface. The application supports both light and dark themes with dynamic theme switching.Material 3 (Material You) is the latest version of Google’s design system, featuring enhanced color systems, updated components, and improved accessibility.
Theme Configuration
The theme system is configured inmain.dart using a stateful approach that allows runtime theme switching.
App Structure
Theme State Management
The theme state is managed inMyAppState:
Light Theme
The light theme uses a seed color approach, generating a complete color scheme from a single base color:Color Scheme Generation
Material 3’sColorScheme.fromSeed() automatically generates:
- Primary, secondary, and tertiary colors
- Container colors and their “on” variants
- Surface colors with appropriate contrast
- Error colors
- Inverse colors for special use cases
The seed color (
Colors.blue) influences the entire color palette, ensuring visual harmony across all UI elements.Dark Theme
The dark theme uses Flutter’s built-in dark theme configuration:- Appropriate contrast ratios for dark environments
- Reduced eye strain in low-light conditions
- Consistent Material 3 styling
- Proper elevation and surface colors
Theme Switching
Accessing Theme State
To toggle the theme from anywhere in the app, use the static accessor:Example: Theme Toggle Button
Here’s how you might implement a theme toggle button:Material 3 Components
With Material 3 enabled, Numix automatically uses updated component styles:Buttons
- FilledButton (high emphasis)
- OutlinedButton (medium emphasis)
- TextButton (low emphasis)
- FloatingActionButton (with updated shapes)
Cards and Containers
- Updated elevation system
- Rounded corners by default
- Better surface color handling
Input Fields
- Filled text fields by default
- Updated focus indicators
- Improved error states
Customizing the Theme
Changing the Seed Color
To change the primary color throughout the app, modify the seed color:Adding Custom Theme Properties
You can extend the theme with additional customizations:Custom Dark Theme Configuration
For more control over the dark theme, use the full constructor:Persisting Theme Preference
To save the user’s theme preference across app restarts, integrate withSharedPreferences:
Accessing Theme Colors
In your widgets, access theme colors through the context:Common Color Usage
primary/onPrimary: Main brand color and text on itsecondary/onSecondary: Accent color and text on itsurface/onSurface: Background surfaces and text on themprimaryContainer/onPrimaryContainer: Contained componentserror/onError: Error states and text
Always use “on” colors for text/icons placed on their corresponding background to ensure proper contrast and accessibility.
Best Practices
- Use theme colors instead of hardcoded colors for consistency
- Test both themes during development to ensure proper contrast
- Follow Material 3 guidelines for component usage
- Consider accessibility by maintaining sufficient contrast ratios
- Use semantic colors (e.g.,
errorfor error states, not red)