[英]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.