Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App theme doesn't update if app is started while the system was in dark mode #32

Closed
Sandai64 opened this issue Feb 15, 2022 · 14 comments
Closed

Comments

@Sandai64
Copy link

Sandai64 commented Feb 15, 2022

Describe the bug
App theme doesn't update if the app is started while the system was in dark mode.
I have only tested this on an Android 11 phone, the Oneplus Nord.

The code

class MyApp extends StatelessWidget
{
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context)
  {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);

    // Auto-reset immersive mode on UI change after 1 sec
    SystemChrome.setSystemUIChangeCallback
    (
      (systemOverlaysAreVisible) => Future.delayed
      (
        const Duration(seconds: 2),
        ()
        {
          SystemChrome.restoreSystemUIOverlays();
        }
      )
    );

    return AdaptiveTheme
    (
      light: AppTheme.lightTheme, // Custom Material theme overrides
      dark: AppTheme.darkTheme,
      initial: AdaptiveThemeMode.system,
      builder: (theme, darkTheme)
      {
        return MaterialApp
        (
          supportedLocales: const
          [
            Locale('en'),
            Locale('fr'), // Fallback lang
          ],

          localizationsDelegates:
          [
            FlutterI18nDelegate
              (
              translationLoader: FileTranslationLoader
                (
                  basePath: 'assets/i18n',
                  fallbackFile: 'fr'
              ),
              missingTranslationHandler: (key, locale)
              {
                if (kDebugMode)
                {
                  print("i18n --- Missing Key: $key, languageCode: ${locale?.languageCode}");
                }
              },
            ),
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate
          ],

          debugShowCheckedModeBanner: true,
          title: 'My App',
          initialRoute: '/',
          routes: AppRoutes.appRoutes,
          theme: theme,
          darkTheme: darkTheme,
        );
      }
    );
  }
}

Environment

  • OS: Android 11
  • adaptive_theme: 2.3.0

Additional info

  • I've noticed that, if I change the system from light/dark mode when the theme isn't updating, I don't even get a log message in my flutter run session. I do get logs notifying a theme change when I start the app when the system is in light mode, however.

  • So far I don't know if the issue is with my code or your package, I'll be very grateful if you could help me on this.

  • Note that the issue appears regardless if the app is in release or debug mode.

@Stratovarius93
Copy link

I have the same error, any solution ?

@gnassro
Copy link

gnassro commented Mar 16, 2022

same problem

@Arfmann21
Copy link

Same here, anyone got a fix?

@BirjuVachhani
Copy link
Owner

BirjuVachhani commented Apr 3, 2022

I have released a fix for system theme change not being detected. Please try v2.3.1 and if this issue is fixed.

@gnassro
Copy link

gnassro commented Apr 4, 2022

I have release a fix for system theme change not being detected. Please try v2.3.1 and if this issue is fixed.

same issue, app theme doesn't update if app is started while the system was in dark mode. only work when the app is started while system not in dark mode

@BirjuVachhani
Copy link
Owner

BirjuVachhani commented Apr 4, 2022

That's strange. I also do have Oneplus Nord CE with Android 11 and when I start my app while system is in dart mode, it works fine for me.

Checkout this part of the docs where the mode is retrieved from storage before loading the app. Maybe this can fix your issue but I am not sure.

To help me reproduce this, could you please create an example app with the same issue and provide exact steps to reproduce? (like does it happen on first run or second run?) At least post the exact code here.

@gnassro
Copy link

gnassro commented Apr 5, 2022

That's strange. I also do have Oneplus Nord CE with Android 11 and when I start my app while system is in dart mode, it works fine for me.

Checkout this part of the docs where the mode is retrieved from storage before loading the app. Maybe this can fix your issue but I am not sure.

To help me reproduce this, could you please create an example app with the same issue and provide exact steps to reproduce? (like does it happen on first run or second run?) At least post the exact code here.

yes you are right, i think there is something wrong in my project, because when i create new project and using the same ThemeData that i used in my project, it worked fine

@BirjuVachhani
Copy link
Owner

@gnassro I thought so. Please check your configuration and make sure you're not changing theme explicitly from somewhere.

@BirjuVachhani
Copy link
Owner

@erwangse Does the latest release work for you?

@gnassro
Copy link

gnassro commented Apr 6, 2022

@gnassro I thought so. Please check your configuration and make sure you're not changing theme explicitly from somewhere.

I discovered that the problem because of using this package https://pub.dev/packages/preload_page_view. when i replace it with the default Widget, it work fine

@BirjuVachhani
Copy link
Owner

@gnassro Ah! I think that package caches widgets so those widgets are not updated when the theme is changed. Although this is not a solution, can you try setting the preloadPagesCount to 0 (if allowed) just to check if that works as widgets shouldn't be cached in that case.

@gnassro
Copy link

gnassro commented Apr 6, 2022

@gnassro Ah! I think that package caches widgets so those widgets are not updated when the theme is changed. Although this is not a solution, can you try setting the preloadPagesCount to 0 (if allowed) just to check if that works as widgets shouldn't be cached in that case.

@BirjuVachhani i tried, but same issue, i think i need to change this package. thanks

@BirjuVachhani
Copy link
Owner

Closing this issue as it seems to be fixed. Feel free to reopen if it does work for some reason.

@Sandai64
Copy link
Author

Hi there, just wanted to make a quick follow-up and add a bit of context to this !
I'm the (currently) sole developer of a flutter app in my company, sorry I didn't respond in time.
As for your first concern, I do cache theme changes in Hive & restore them on startup.
And as for your second, the new release seems to work just fine ! Thanks ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants