Sparround

Theming and Material 3

Colours and fonts should not be hardcoded inside widgets. The central place in Flutter is `ThemeData`: you pass it to MaterialApp(theme: ...) and read it anywhere down the tree with Theme.of(context).

Material 3 (Flutter's modern default) simplifies this: a whole coordinated colour scheme is generated from a single seedColor:

  • ColorScheme.fromSeed(seedColor: ...) — once for light, once for dark
  • you supply theme and darkTheme, and themeMode decides which is active
  • ThemeMode.system follows the device setting
ApproachResult
Hardcoding `Colors.blue` in a widgetUnreadable in dark mode; a brand change means editing every file
`Theme.of(context).colorScheme.primary`Correct in both modes, changed from one place
Writing `TextStyle(fontSize: 16)`Typography drifts between screens
`Theme.of(context).textTheme.bodyLarge`Consistent typography that respects accessibility settings

Interview tip. The right answer to "how do you support dark mode?" is not "I check a flag and use black". A strong answer: I define theme and darkTheme separately, follow the device with themeMode: ThemeMode.system, and keep every colour out of widget code — it all comes from colorScheme. One step further: mention that ColorScheme.fromSeed derives contrast-appropriate pairs for you.

📚 Sources and documentation