0
0
Fluttermobile~20 mins

Dark mode support in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dark Mode Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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?
}
Aif (MediaQuery.of(context).brightness == ThemeMode.dark) { return Text('Dark mode'); } else { return Text('Light mode'); }
Bif (brightness == ThemeMode.dark) { return Text('Dark mode'); } else { return Text('Light mode'); }
Cif (Theme.of(context).brightness == Brightness.dark) { return Text('Dark mode'); } else { return Text('Light mode'); }
Dif (brightness == Brightness.dark) { return Text('Dark mode'); } else { return Text('Light mode'); }
Attempts:
2 left
💡 Hint
Use MediaQuery to get platformBrightness and compare with Brightness.dark.
lifecycle
intermediate
2:00remaining
Responding to dark mode changes dynamically
In Flutter, which widget automatically rebuilds when the system dark mode setting changes?
AMaterialApp with themeMode set to ThemeMode.system
BStatelessWidget with a fixed ThemeData
CContainer widget with a background color
DStatefulWidget that listens to platformBrightness manually
Attempts:
2 left
💡 Hint
Flutter's MaterialApp can adapt themes automatically when themeMode is set properly.
📝 Syntax
advanced
2:00remaining
Correct dark theme definition in Flutter
Which option correctly defines a dark theme with a primary color of blue in Flutter?
Afinal darkTheme = ThemeData(themeMode: ThemeMode.dark, primaryColor: Colors.blue);
Bfinal darkTheme = ThemeData.dark(primaryColor: Colors.blue);
Cfinal darkTheme = ThemeData(brightness: Brightness.dark, primaryColor: Colors.blue);
Dfinal darkTheme = ThemeData(brightness: ThemeMode.dark, primaryColor: Colors.blue);
Attempts:
2 left
💡 Hint
Use ThemeData constructor with brightness set to Brightness.dark.
🔧 Debug
advanced
2: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(),
);
AThe app's widgets do not use Theme.of(context) to get colors, so theme changes have no effect.
BThe device does not support dark mode, so the app cannot switch.
CThe themeMode property is ignored unless explicitly set to ThemeMode.dark.
DThe darkTheme is missing primaryColor, so it defaults to light mode.
Attempts:
2 left
💡 Hint
Check if widgets use the theme colors dynamically.
🧠 Conceptual
expert
2:00remaining
Best practice for custom dark mode support
Which approach best supports dark mode in a Flutter app with custom colors and fonts?
AUse only a light theme and manually change colors in widgets based on platformBrightness.
BDefine separate ThemeData objects for light and dark themes and switch using themeMode: ThemeMode.system.
CUse ThemeData.light() and override colors dynamically in each widget build method.
DIgnore system dark mode and provide a toggle button that switches colors manually.
Attempts:
2 left
💡 Hint
Flutter's theming system is designed to handle multiple themes cleanly.