How do you make your app follow the system dark/light mode preference?
Setting themeMode: ThemeMode.system in MaterialApp makes the app follow the device's dark/light mode setting.
Implement dark mode support and load custom fonts into your app
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Dark mode and custom fonts are two of the most impactful visual improvements you can make in any app. Flutter makes both straightforward to implement. Dark mode reduces eye strain in low light and saves battery on OLED screens. Custom fonts give your app a unique personality that sets it apart from the default Material look.
1// ── Dark Mode with ThemeData ──2MaterialApp(3themeMode: ThemeMode.system, // system, light, or dark4theme: ThemeData(5colorScheme: ColorScheme.fromSeed(6seedColor: Colors.blue,7brightness: Brightness.light,8),9),10darkTheme: ThemeData(11colorScheme: ColorScheme.fromSeed(12seedColor: Colors.blue,13brightness: Brightness.dark, // dark variant14),15),16home: const HomeScreen(),17)1819// ── Check current theme in a widget ──20@override21Widget build(BuildContext context) {22final isDark = Theme.of(context).brightness == Brightness.dark;2324return Container(25color: isDark ? Colors.grey[900] : Colors.white,26child: Text(27'Hello',28style: TextStyle(29color: isDark ? Colors.white : Colors.black,30),31),32);33}
1// ── Custom Fonts ──2// 1. Add font files to assets/fonts/ folder3// 2. Register in pubspec.yaml:4//5// flutter:6// fonts:7// - family: Poppins8// fonts:9// - asset: assets/fonts/Poppins-Regular.ttf10// - asset: assets/fonts/Poppins-Bold.ttf11// weight: 70012// - asset: assets/fonts/Poppins-Italic.ttf13// style: italic1415// 3. Use in ThemeData:16MaterialApp(17theme: ThemeData(18fontFamily: 'Poppins', // applied app-wide19textTheme: const TextTheme(20displayLarge: TextStyle(fontFamily: 'Poppins', fontWeight: FontWeight.bold),21bodyMedium: TextStyle(fontFamily: 'Poppins'),22),23),24)2526// 4. Or use directly on a widget:27Text(28'Custom font text',29style: TextStyle(30fontFamily: 'Poppins',31fontWeight: FontWeight.w700,32fontSize: 20,33),34)
Use the google_fonts package for easy access to over 1000 fonts without downloading or managing font files manually. Add google_fonts to your pubspec.yaml and use it like GoogleFonts.poppins(fontSize: 20, fontWeight: FontWeight.bold) anywhere you need a custom font style.
Dark mode is not just color inversion.
Readable typography is more important than aesthetic experimentation.
Implement dark mode support and load custom fonts into your app. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Connect each concept to real app features you can build.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
Setting themeMode: ThemeMode.system in MaterialApp makes the app follow the device's dark/light mode setting.
Custom fonts must be declared in pubspec.yaml under the flutter: fonts: section before they can be used.
You can set fontFamily in ThemeData (applies to Text using defaultStyle) or wrap a subtree with DefaultTextStyle to override font family.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue