Colors class provides named Material Design colors and utility functions for working with colors in Flet.
Overview
Flet includes all Material Design colors with multiple shades and accent variations. Colors can be used throughout your application for backgrounds, text, borders, and more.Color Categories
Theme Colors
Dynamic colors that adapt to your app’s theme:Basic Colors
Material Color Palette
Each Material color comes in 10 shades (50, 100, 200, …, 900) and accent variants: Red:Opacity Variants
Utility Methods
random
Selects a random color, with optional exclusions and weights.exclude: A list of Colors to exclude from selectionweights: A dictionary mapping color members to their respective weights for weighted random selection
- A randomly selected color, or None if all members are excluded
with_opacity
Returns a color with the given opacity.opacity: The opacity value between 0.0 and 1.0color: The color to apply opacity to
- A string representing the color with opacity, in the format
"color,opacity"
ValueError: If the opacity is not between 0 and 1 (inclusive)
Usage Examples
Basic Color Usage
Color Shades
Theme-Aware Colors
Custom Color Strings
You can also use custom colors as hex strings:When to Use Each Color Type
- Theme colors (PRIMARY, SECONDARY, etc.): Use for consistent theming that adapts to light/dark modes
- Material palette (BLUE_500, RED_300, etc.): Use for specific, consistent colors
- Accent colors: Use for highlighted elements that need to stand out
- Opacity variants: Use for overlays, shadows, and subtle backgrounds
- Custom hex: Use when you need brand-specific colors not in the Material palette