Home > Net >  Check if ThemeMode.system is dark or light
Check if ThemeMode.system is dark or light

Time:09-15

I'm working on a mobile application and I want to have ThemeMode.system by default, but I want to make it so that the user can change it. Then I have a IconButton that should have Icons.dark_mode if the system theme is dark and Icons.light_mode if the system theme is white. I tried this:


Icon themeIcon = Icon(ThemeMode.system == ThemeMode.dark ? Icons.dark_mode : Icons.light_mode);

but it turns out that ThemeMode.system can't be one of them. So, how can I set the Icon based of that?

CodePudding user response:

You might be looking for

Theme.of(context).brightness == Brightness.light
Theme.of(context).brightness == Brightness.dark

Here is the appropriate documentation

  • Related