简体   繁体   English

Flutter App中的状态恢复闪烁/闪烁屏幕

[英]State resume in Flutter App flash / flicker the screen

I have implemented the dark & light theme in my app according the device settings mode.我已经根据设备设置模式在我的应用程序中实现了深色和浅色主题。

I put the app in background and when I come back I'm seeing some flashes/flickering on Resume.我将应用程序置于后台,当我回来时,我看到 Resume 上有一些闪烁/闪烁。

Here is a random page in my app to observe the behavior :这是我的应用程序中用于观察行为的随机页面:

在此处输入图像描述

The behavior is like the Light theme was reset first on Resume, and then remember that this is actually the Dark theme set.该行为就像在 Resume 上首先重置 Light 主题,然后记住这实际上是 Dark 主题集。 Then I supposed the main App Theme could be reloaded on state Resume but I'm not very sure.然后我认为可以在状态 Resume 上重新加载主应用程序主题,但我不太确定。

Is the material app reloaded on Resume ?材料应用程序是否在 Resume 上重新加载?

Here is my MaterialApp :这是我的MaterialApp

MaterialApp(
              navigatorKey: NavigationService.navigatorKey,
              theme: ThemeProvider.instance.getLightTheme(),
              darkTheme: ThemeProvider.instance.getDarkTheme(),
              themeMode: ThemeProvider.instance.getThemeMode(),
              locale: Locale(SharedPreferencesManager.instance.getLocale()),
              debugShowCheckedModeBanner: false,
              localizationsDelegates: const [
                LocalizationDelegate(),
                CountryLocalizations.delegate,
                GlobalCupertinoLocalizations.delegate,
                GlobalMaterialLocalizations.delegate,
                GlobalWidgetsLocalizations.delegate,
              ],
              supportedLocales: LocaleManager().getSupportedLocale(),
              home: WillPopScope(
                onWillPop: () async => false,
                child: const HomePage(),
              ));

The theme provider manager methods for theme :主题的主题提供者管理器方法:

ThemeMode getThemeMode() {
    if (SharedPreferencesManager.instance.getTheme() == "dark") {
      onDarkMode = true;
      return ThemeMode.dark;
    } else if (SharedPreferencesManager.instance.getTheme() == "light") {
      onDarkMode = false;
      return ThemeMode.light;
    } else {
      return ThemeMode.system;
    }
  }

  ThemeData getDarkTheme() {
    return ThemeData.dark().copyWith(
      scaffoldBackgroundColor: Colors.black,
      primaryColor: shadow,
      primaryColorLight: shadow2,
      shadowColor: Colors.transparent,
      splashColor: Colors.transparent,
      highlightColor: shadow,
      dialogBackgroundColor: shadow,
      brightness: Brightness.dark,
      dividerTheme: DividerThemeData(
        color: Colors.white.withOpacity(0.1),
        thickness: 0.5,
        space: 0,
      ),
      textTheme: const TextTheme(
          headline1: TextStyle(
              fontSize: 16, fontWeight: FontWeight.bold, color: highlight),
          headline2: TextStyle(
              fontSize: 14, fontWeight: FontWeight.bold, color: highlight),
          bodyText1: TextStyle(
            fontSize: 16,
            color: highlight,
          ),
          bodyText2: TextStyle(
            fontSize: 14,
            color: highlight,
          ),
          subtitle1: TextStyle(
              fontSize: 22, fontWeight: FontWeight.bold, color: highlight),
          subtitle2: TextStyle(
              fontSize: 18, fontWeight: FontWeight.bold, color: highlight)),
      // Android over scroll
      colorScheme:
          ColorScheme.fromSwatch().copyWith(secondary: Colors.transparent),
    );
  }

  ThemeData getLightTheme() {
    return ThemeData.light().copyWith(
        //scaffoldBackgroundColor: Colors.white,
        splashColor: Colors.transparent,
        primaryColor: Colors.white,
        primaryColorLight: light,
        shadowColor: elevationColor,
        brightness: Brightness.light,
        highlightColor: light,
        dialogBackgroundColor: Colors.white,
        dividerColor: light.withOpacity(0.5),
        dividerTheme: DividerThemeData(
            color: light.withOpacity(0.5), thickness: 0.5, space: 0),
        textTheme: const TextTheme(
            headline1: TextStyle(
                fontSize: 16, fontWeight: FontWeight.bold, color: shadow),
            headline2: TextStyle(
                fontSize: 14, fontWeight: FontWeight.bold, color: shadow),
            bodyText1: TextStyle(fontSize: 16, color: shadow),
            bodyText2: TextStyle(fontSize: 14, color: shadow),
            subtitle1: TextStyle(
                fontSize: 22, color: shadow, fontWeight: FontWeight.bold),
            subtitle2: TextStyle(
                fontSize: 18, color: shadow, fontWeight: FontWeight.bold)),
        colorScheme:
            ColorScheme.fromSwatch().copyWith(secondary: Colors.transparent));
  }

This behavior is not happening for 100% but let say 1 time on 5 while resuming and never on start state (first time launch).这种行为不是 100% 发生的,而是在 5 上说 1 次,同时恢复并且从不处于启动状态(第一次启动)。

Can someone tell me if I made a mistake to get this result on some config ?有人可以告诉我,如果我在某些配置上得到这个结果是错误的吗?

Is this related to the theme ?这与主题有关吗? Or maybe nothing at all或者可能什么都没有

这个问题似乎在 Flutter 3 版本中得到修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM