How ColorScheme.fromSeed works
ColorScheme.fromSeed does not use your seed colour directly. It converts the seed to HCT (hue, chroma, tone), a colour space Google built for Material 3. Tone is perceived lightness from 0 (black) to 100 (white), so two colours with the same tone look equally light whatever their hue. That is what makes the contrast between roles predictable.
From the seed’s hue, the default tonalSpot variant builds five tonal palettes, each a single hue and chroma at every tone:
- Primary: the seed’s hue at chroma 36, which is why a very bright seed comes out calmer.
- Secondary: the same hue at chroma 16, a muted companion.
- Tertiary: the hue turned 60 degrees, at chroma 24, for accents.
- Neutral and neutral variant: the same hue at chroma 6 and 8, used for surfaces, text and outlines.
- Error: a fixed red palette, the same for every seed.
Each role then takes a tone from its palette. In the light scheme primary is tone 40, onPrimary 100,primaryContainer 90 and onPrimaryContainer 10. The dark scheme flips them: primary 80,onPrimary 20, primaryContainer 30 and onPrimaryContainer 90. Surfaces sit near the ends of the neutral palette: tone 98 for surface in light mode and tone 6 in dark mode, with the surfaceContainer levels stepping between them. If a pair does not reach its minimum contrast, the tone is nudged until it does.
Because of this, the primary you get is usually not your seed. A seed of #6750A4 gives a lightprimary of #65558F. If your brand colour has to appear exactly, use the full ColorScheme output and set that role by hand, or pass it to fromSeed as an override, for example primary: Color(0xFF6750A4).
Using the code in your app
- Save the download as
lib/theme/app_theme.dart, or paste the code into any file underlib/. - Import it in
main.dartand pass both themes toMaterialApp:theme: AppTheme.light,darkTheme: AppTheme.darkandthemeMode: ThemeMode.systemto follow the phone’s setting. - In widgets, read colours from the theme instead of hard-coding them:
Theme.of(context).colorScheme.primary,colorScheme.surfaceContainerHighand so on. Material widgets already pick the right roles on their own.
The code needs Flutter 3.22 or newer. It sets useMaterial3: true, which has been the default since Flutter 3.16, so it is there to make the intent clear rather than to change anything.
fromSeed or the full ColorScheme?
The fromSeed output is short and easy to change: swap the seed and the whole app follows. The colours are calculated when the app runs, so they can shift slightly if a future Flutter release updates its colour algorithm, as has happened before.
The full ColorScheme output writes every role as a fixed Color(0xFF…) in a const ColorScheme. Use it when a designer signs off on exact values, when you need to tweak a single role such as outline, or when screenshots and golden tests must stay identical across Flutter upgrades.
Role changes in Flutter 3.22
Flutter 3.22 brought ColorScheme in line with the current Material 3 colour roles. It added surfaceDim,surfaceBright and five container levels from surfaceContainerLowest to surfaceContainerHighest. Cards, menus, dialogs, navigation bars and other components now use these containers to show depth with colour instead of the older tinted elevation overlay.
At the same time background and onBackground were deprecated in favour of surface andonSurface, and surfaceVariant in favour of surfaceContainerHighest. The generated code only uses the current names, so it does not trigger deprecation warnings. If you are upgrading an older theme, replace those three names first.
Dynamic colour on Android 12 and newer
Android 12 and newer can build a colour scheme from the user’s wallpaper. The dynamic_color package gives you that scheme in Flutter through DynamicColorBuilder. A common pattern is to use the wallpaper scheme when the device provides one and fall back to the theme generated here on iOS, the web, desktop and older Android versions. If your brand colours matter more than matching the wallpaper, skip dynamic colour and use this theme everywhere.
Contrast and accessibility
The tone gaps between pairs are chosen for legibility. Text roles such as onSurface and onPrimary aim for at least 4.5:1 against their background, the WCAG AA level for body text, and outline aims for 3:1, enough for component borders. The contrast list under the preview shows the real ratios for your seed.
Pairing matters more than the colours themselves: put onPrimaryContainer text on primaryContainer, not onsurface. And if you change a role by hand in the full ColorScheme, check its partner again, because the automatic contrast adjustment no longer applies to it.
Questions
Why doesn’t the primary colour match my seed?
The tonal spot scheme keeps the seed’s hue but uses its own chroma (36) and tone (40 in light mode, 80 in dark mode). That keeps text and buttons readable for any seed. To force an exact brand colour, set primary yourself, either as a fromSeed override or in the full ColorScheme.
Will these colours match my Flutter app exactly?
They come from a port of material-color-utilities, the library Flutter uses for ColorScheme.fromSeed, with the default tonal spot variant and standard contrast. Flutter 3.22 and later should give the same values. If a later release changes the algorithm, the full ColorScheme output keeps your colours fixed.
What do the custom secondary and tertiary colours do?
They replace that palette with one built from the colour you pick, keeping its own hue and chroma, and the generated code sets those four roles explicitly. Flutter’s fromSeed on its own cannot do this, so the overrides are written into the code.
Is anything sent to a server?
No. The colour maths and the code generator are JavaScript running in this page. Nothing is saved or sent.
Related guide: read Flutter Material 3 theming: ColorScheme.fromSeed explained to see why your seed colour changes and how to control every role.
Need a Flutter app that looks this polished in both light and dark mode? I’m Muhammad Naeem, a Flutter developer with 10+ apps live on the stores. Tell me about your project.