Component - Dark mode support
This UI component shows how an app can switch between light and dark themes. It changes colors to be easier on the eyes in dark environments, improving comfort and battery life.
This UI component shows how an app can switch between light and dark themes. It changes colors to be easier on the eyes in dark environments, improving comfort and battery life.
MaterialApp
└── Scaffold
├── AppBar
│ └── Text
└── Center
└── Column
├── Text
└── SwitchdarkTheme in a Flutter app?darkThemedarkTheme property in MaterialApp defines how the app looks when dark mode is active.theme property is for light mode, and darkTheme is specifically for dark mode appearance.darkTheme sets dark mode style [OK]MaterialApp?themeMode: ThemeMode.dark tells Flutter to use the dark theme.darkTheme defines the dark mode appearance.themeMode: ThemeMode.dark and provide darkTheme -> Option AMaterialApp(
theme: ThemeData(primaryColor: Colors.white),
darkTheme: ThemeData(primaryColor: Colors.black),
themeMode: ThemeMode.system,
home: Scaffold(
backgroundColor: Theme.of(context).primaryColor,
),
)themeMode is system, Flutter uses darkTheme if device is in dark mode.darkTheme sets primaryColor to black, so backgroundColor will be black.MaterialApp( theme: ThemeData.light(), darkTheme: ThemeData.dark(), home: HomeScreen(), )
themeMode, Flutter defaults to light mode and ignores darkTheme.ThemeData.dark() is valid, so no error there.themeMode property to switch themes -> Option BthemeMode must be dynamic based on user choice.themeMode accordingly, while providing theme and darkTheme.theme, darkTheme, and control themeMode with a user setting stored in state -> Option DPass the test and this pattern moves unknown