Search code examples
flutterbrightnessios15

Change platform brigtness is triggered when 'Home' is pressed in iOS 15 Simulator


I'm having an issue after my Simulator was updated to iOS 15 in my upcoming Flutter app. When I press the 'Home' button at the top it causes my app to fire the didChangePlatformBrightness() function twice.

Seriously thinking on remove this check while the app is already open and leave it only at startup. Anyone with the same problem and any tips on how to solve it?

On Android everything works fine, just as expected.


Solution

  • I solved this question by monitoring the App lifecycle state. If the app is in resumed state, then I change the color scheme, otherwise I'll do nothing. It occurs because when you press the Home button, the app state changes. See the example below:

    void didChangePlatformBrightness() {
        if (appState == AppLifecycleState.resumed) {
          //give the user a choice for restarting the app, so the colors will 
          //all be set correctly
          showThemeChangeWarning(); 
          setColorScheme(); 
          super.didChangePlatformBrightness();
        }
      }