Birio
Birio

Reputation: 65

Check if ThemeMode.system is dark or light

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?

Upvotes: 5

Views: 4031

Answers (1)

jraufeisen
jraufeisen

Reputation: 3877

You might be looking for

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

Here is the appropriate documentation

Upvotes: 11

Related Questions