[英]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,
),
);
但是在这种情况下从不应用强调色,无论设置什么辅助颜色,强调色始终是蓝色。 所以 - 弃用的方法工作得很好,新的方法不行。
有任何想法吗?
如果您正在寻找Radio
和Checkbox
的颜色变化,那么它会从toggleableActiveColor
主题属性中获取强调色。
您需要像这样在主题中使用该属性。
theme: ThemeData(
//...
toggleableActiveColor : Colors.red
//...
home: ...,
localizationsDelegates: [
//...
],
supportedLocales: [
const Locale('pl', 'PL'),
],
routes: routes,
),
有关更多属性更改,请查看此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.