How to manually set dark mode in flutter using ThemeData in Flutter?
I am currently using ThemeData to handle my darkMode events:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
themeMode: ThemeMode.system,
theme: MainTheme.light,
darkTheme: MainTheme.dark,
home: HomeScreen(),
debugShowCheckedModeBanner: false,
);
}
}
I wanted to know, how to turn on dark mode manually in Flutter when I see a specific widget? In every Widget I make, I use this code to create a variable that checks if dark mode is activated or not so I can manually manage the colors:
var brightness = MediaQuery.of(context).platformBrightness;
darkModeOn = brightness == Brightness.dark;