[英]Flutter: ColorScheme.secondary never applied to set accent color
My code - accent color set with deprecated accentColor
property, it works, red color applied:我的代码 - 带有不推荐使用的
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,
),
);
I migrated to ColorScheme
call this way:我以这种方式迁移到
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,
),
);
But accent color is never applied in this case, no mater what secondary color is set, accent color is always blue.但是在这种情况下从不应用强调色,无论设置什么辅助颜色,强调色始终是蓝色。 So - deprecated approach works just fine, new approach does not.
所以 - 弃用的方法工作得很好,新的方法不行。
Any ideas?有任何想法吗?
If you looking for color changes for Radio
and Checkbox
then it pick up the accent color from toggleableActiveColor
theme property.如果您正在寻找
Radio
和Checkbox
的颜色变化,那么它会从toggleableActiveColor
主题属性中获取强调色。
You need to use that property in the theme like this.您需要像这样在主题中使用该属性。
theme: ThemeData(
//...
toggleableActiveColor : Colors.red
//...
home: ...,
localizationsDelegates: [
//...
],
supportedLocales: [
const Locale('pl', 'PL'),
],
routes: routes,
),
For more properties changes check this document .有关更多属性更改,请查看此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.