繁体   English   中英

Flutter:ColorScheme.secondary 从未应用于设置强调色

[英]Flutter: ColorScheme.secondary never applied to set accent color

我的代码 - 带有不推荐使用的accentColor属性的强调色设置,它可以工作,应用红色:

return VersionBanner(
      text: "DEV",
      visible: globals.isDev,
      location: BannerLocation.bottomEnd,
      child: MaterialApp(
        title: 'MyApp',
        theme: ThemeData(
          accentColor: Colors.red,
          appBarTheme: AppBarTheme(
            elevation: 0,
            backgroundColor: Colors.white,
            foregroundColor: Colors.black,
            systemOverlayStyle: overlayStyle,
          ),
          scaffoldBackgroundColor: Colors.white,
          primaryColor: Colors.white,
          textTheme: AppTheme.textTheme,
          pageTransitionsTheme: PageTransitionsTheme(builders: {
            TargetPlatform.android: ZoomPageTransitionsBuilder(),
            TargetPlatform.iOS: CupertinoPageTransitionsBuilder()
          }),
        ),
        home: globals.isLogged ? HomePage() : LoginPage(),
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          DefaultMaterialLocalizations.delegate,
          DefaultCupertinoLocalizations.delegate
        ],
        supportedLocales: [
          const Locale('pl', 'PL'),
        ],
        routes: routes,
      ),
    );

我以这种方式迁移到ColorScheme调用:

return VersionBanner(
      text: "DEV",
      visible: globals.isDev,
      location: BannerLocation.bottomEnd,
      child: MaterialApp(
        title: 'MyApp',
        theme: ThemeData(
          appBarTheme: AppBarTheme(
            elevation: 0,
            backgroundColor: Colors.white,
            foregroundColor: Colors.black,
            systemOverlayStyle: overlayStyle,
          ),
          scaffoldBackgroundColor: Colors.white,
          primaryColor: Colors.white,
          textTheme: AppTheme.textTheme,
          pageTransitionsTheme: PageTransitionsTheme(builders: {
            TargetPlatform.android: ZoomPageTransitionsBuilder(),
            TargetPlatform.iOS: CupertinoPageTransitionsBuilder()
          }), colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.red),
        ),
        home: globals.isLogged ? HomePage() : LoginPage(),
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          DefaultMaterialLocalizations.delegate,
          DefaultCupertinoLocalizations.delegate
        ],
        supportedLocales: [
          const Locale('pl', 'PL'),
        ],
        routes: routes,
      ),
    );

但是在这种情况下从不应用强调色,无论设置什么辅助颜色,强调色始终是蓝色。 所以 - 弃用的方法工作得很好,新的方法不行。

有任何想法吗?

如果您正在寻找RadioCheckbox的颜色变化,那么它会从toggleableActiveColor主题属性中获取强调色。

您需要像这样在主题中使用该属性。

    theme: ThemeData(
     //...
      toggleableActiveColor : Colors.red
    //...
    home: ...,
    localizationsDelegates: [
      //...
    ],
    supportedLocales: [
      const Locale('pl', 'PL'),
    ],
    routes: routes,
  ),

有关更多属性更改,请查看此文档

暂无
暂无

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

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