FlutterBasic 2 min read

Flutter themes and dark mode with ColorScheme

Centralize colors and typography, follow system theme preferences and avoid unreadable hard-coded combinations.

On this page

A theme is a shared design contract. Defining it centrally makes component states, typography and color choices easier to keep consistent across screens.

Start with a color scheme

Generate a light and dark ColorScheme from a seed, then let Material components consume those roles. The fragment below belongs around your app’s home widget.

Worked example

This is a focused code fragment. Place it in the class or file described above; it is not a complete standalone app.

MaterialApp(
  theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo)),
  darkTheme: ThemeData(colorScheme: ColorScheme.fromSeed(
    seedColor: Colors.indigo, brightness: Brightness.dark)),
  themeMode: ThemeMode.system,
  home: const HomePage(),
)

Read the result

ThemeMode.system follows the platform preference. HomePage is your own widget. Components using the scheme can adapt coherently; a container with a fixed white background and fixed light text cannot.

Follow a semantic color instead of a raw color value

A component should ask for a role such as surface or primary rather than assuming white always means background and black always means text. A ColorScheme gives those roles coherent values for the current brightness and state.

When the system preference changes, ThemeMode.system can select the matching theme. Widgets that consume theme values can adapt together. A manually painted white region with a fixed light foreground can remain unreadable even though MaterialApp correctly changed modes.

Check enabled, disabled, error and focus states, not only the default screenshot. Then test the same screen with larger text. The accessibility guide connects visual contrast and semantics with the broader interaction contract.

Practice and verification

Create a sample screen with a heading, input and disabled button. Check light and dark modes, error colors and focus states. Replace a hard-coded color with a semantic scheme role and compare.

How this topic connects

Understand first

Apply it next

Lesson progressMark complete after checking the example and exercise.

Find your next idea

Search lessons, code examples and projects.

Type a few words to start exploring.