Themes, Material 3, Colors and Fonts

Google Flutter 11 min min read Updated: Nov 16, 2026 Intermediate
Themes, Material 3, Colors and Fonts
Intermediate Topic 8 of 9

Why Use a Theme?

A theme stores your app's colors, fonts and widget styles in one place. Change it once and the whole app updates. It also makes dark mode almost free. Since Flutter 3.16, Material 3 is the default look.

One Color Creates a Palette

dart MaterialApp( title: 'My App', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal), ), darkTheme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.teal, brightness: Brightness.dark, ), ), themeMode: ThemeMode.system, // follow the phone setting home: const HomePage(), )

ColorScheme.fromSeed makes a complete, accessible set of colors from one seed color: primary, secondary, surface, error and more.

Use Theme Colors in Widgets

dart final scheme = Theme.of(context).colorScheme; Container( color: scheme.primaryContainer, child: Text('Hello', style: TextStyle(color: scheme.onPrimaryContainer)), )
Why not Colors.red? Fixed colors do not change in dark mode. Colors from the colorScheme always have enough contrast on their matching background.
ColorScheme roleUse
primary / onPrimaryMain buttons and their text
secondary / tertiaryAccents
surface / onSurfaceCards, sheets and text on them
error / onErrorErrors

Switch Between Light and Dark

dart ThemeMode mode = ThemeMode.light; // In a StatefulWidget: Switch( value: mode == ThemeMode.dark, onChanged: (dark) => setState(() { mode = dark ? ThemeMode.dark : ThemeMode.light; }), )

Text Theme and Component Themes

dart ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo), textTheme: const TextTheme( headlineMedium: TextStyle(fontWeight: FontWeight.bold), ), appBarTheme: const AppBarTheme(centerTitle: true), elevatedButtonTheme: ElevatedButtonThemeData( style: ElevatedButton.styleFrom( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), ), ), inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder()), )

Custom Fonts with google_fonts

bash flutter pub add google_fonts
dart import 'package:google_fonts/google_fonts.dart'; ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo), textTheme: GoogleFonts.poppinsTextTheme(), )

Custom Fonts from Files

yaml flutter: fonts: - family: Pacifico fonts: - asset: assets/fonts/Pacifico-Regular.ttf
dart Text('Hello', style: TextStyle(fontFamily: 'Pacifico'))
Tip: Define colors and styles in one app_theme.dart file. Then your widgets never contain random hex colors.

Conclusion

A theme gives you consistency and dark mode with very little code. Start with ColorScheme.fromSeed and read colors from the theme.

Quick Summary: Use ThemeData with ColorScheme.fromSeed, set darkTheme and themeMode, and read colors from Theme.of(context).

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators