Challenge - 5 Problems
Dark Mode Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Detecting system dark mode in Flutter
Which code snippet correctly detects if the system is currently using dark mode in a Flutter widget's build method?
Flutter
Widget build(BuildContext context) {
final brightness = MediaQuery.of(context).platformBrightness;
// Which option correctly checks for dark mode?
}Attempts:
2 left
💡 Hint
Use MediaQuery to get platformBrightness and compare with Brightness.dark.
✗ Incorrect
MediaQuery.of(context).platformBrightness returns Brightness.dark or Brightness.light. Comparing it with Brightness.dark detects dark mode. ThemeMode is not used here.
❓ lifecycle
intermediate2:00remaining
Responding to dark mode changes dynamically
In Flutter, which widget automatically rebuilds when the system dark mode setting changes?
Attempts:
2 left
💡 Hint
Flutter's MaterialApp can adapt themes automatically when themeMode is set properly.
✗ Incorrect
MaterialApp with themeMode: ThemeMode.system listens to system theme changes and rebuilds accordingly. StatelessWidget or Container alone do not respond to system changes automatically.
📝 Syntax
advanced2:00remaining
Correct dark theme definition in Flutter
Which option correctly defines a dark theme with a primary color of blue in Flutter?
Attempts:
2 left
💡 Hint
Use ThemeData constructor with brightness set to Brightness.dark.
✗ Incorrect
ThemeData(brightness: Brightness.dark, primaryColor: Colors.blue) correctly sets dark theme with blue primary color. ThemeMode is not a brightness value. ThemeData.dark() does not accept parameters.
🔧 Debug
advanced2:00remaining
Why does the app not switch to dark mode?
A Flutter app uses MaterialApp with themeMode: ThemeMode.system, but it never switches to dark mode even when the system is in dark mode. What is the most likely cause?
Flutter
MaterialApp( theme: ThemeData.light(), darkTheme: ThemeData(brightness: Brightness.dark), themeMode: ThemeMode.system, home: HomeScreen(), );
Attempts:
2 left
💡 Hint
Check if widgets use the theme colors dynamically.
✗ Incorrect
If widgets use fixed colors instead of Theme.of(context).colorScheme or Theme.of(context).primaryColor, the theme change won't affect their appearance. The themeMode and darkTheme are correctly set.
🧠 Conceptual
expert2:00remaining
Best practice for custom dark mode support
Which approach best supports dark mode in a Flutter app with custom colors and fonts?
Attempts:
2 left
💡 Hint
Flutter's theming system is designed to handle multiple themes cleanly.
✗ Incorrect
Defining separate ThemeData for light and dark themes and switching with themeMode: ThemeMode.system is the cleanest and most maintainable approach. Manual color changes in widgets are error-prone and harder to maintain.