2

I am trying to implement dark mode in my flutter app, but I don't know what am I missing but it doesn't work on iOS. I manage to run it on Android just fine, but when I print WidgetsBinding.instance.window.platformBrightness there is still light, event when dark mode is on.

When I set themeMode: ThemeMode.dark - dark mode is working, problem is with the automatic detection.

Also, when I run new blank project, dark mode worked fine. But in my app, which is builded, it does not work. Even if themeMode is set to ThemeMode.system:

      themeMode: ThemeMode.system,
      theme: ThemeData(
        accentColor: darkBlue,
        cursorColor: red,
        primaryColor: Colors.white,
        brightness: Brightness.light,
      ),
      darkTheme: ThemeData(
        accentColor: Colors.white,
        cursorColor: red,
        primaryColor: Colors.white,
        brightness: Brightness.dark,
      ),

Do you have any idea, what could be wrong or do you have any suggestions?

Flutter version: 1.12.13-hotfix.9 and iOS version: iPhone SE simulator - iOS 13.3

Thanks a lot.

mixable
  • 1,068
  • 2
  • 12
  • 42
Petr Jelínek
  • 1,259
  • 1
  • 18
  • 36

1 Answers1

6

I figure it out - just simply removed this entry from info.plist that I have added before.

<key>UIUserInterfaceStyle</key>
<string>Light</string>
Petr Jelínek
  • 1,259
  • 1
  • 18
  • 36
  • 1
    For those who are wondering: this also prevents `WidgetsBindingObserver.didChangePlatformBrightness()` from being called, because the `UIUserInterfaceStyle` is always `Light` and never changing. Thx!! – mixable Jan 06 '21 at 18:32