BirjuVachhani / adaptive_theme

Easiest way to add support for light and dark theme in your flutter app.
https://pub.dev/packages/adaptive_theme
Apache License 2.0
464 stars 37 forks source link

Check whether .system is light or dark #59

Closed eauw closed 4 months ago

eauw commented 4 months ago

Is your feature request related to a problem? Please describe. I'm initializing AdaptiveTheme() with initial: AdaptiveThemeMode.system, for best user experience. But for later ui logic like picking the light or dark logo I can't know if the system is light or dark.

Describe the solution you'd like I would like to do something like AdaptiveTheme.of(context).mode.isSystem == AdaptiveThemeMode.light to check what system is currently. But both checks always return false.

BirjuVachhani commented 4 months ago

Hey @eauw,

Seems you want to know brightness information to determine whether you should show light or dark logo. Easiest way is to use brightness either from your Theme or AdaptiveTheme.

// option 1
AdaptiveTheme.of(context).brightness == Brightness.dark
// option 2
Theme.of(context).brightness == Brightness.light

Another way to know the system brightness is (however you should only do this when theme mode is set to system, Above solution works always though)

final brightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;

I hope this helps! Feel free to reopen the issue if this doesn't work for you!

eauw commented 4 months ago

@BirjuVachhani thank you very much! Exactly what I needed.