【发布时间】:2022-06-30 05:58:34
【问题描述】:
在 VSCode 中,Flutter 向我抱怨“'accentColor' is deprecated and shouldn't be used. Use colorScheme.secondary instead. For more information, consult the migration guide at https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties#migration-guide. This feature was deprecated after v2.3.0-0.1.pre.. Try replacing the use of the deprecated member with the replacement.”
迁移指南建议这样做:
迁移前的代码:
MaterialApp(
theme: ThemeData(accentColor: myColor),
// ...
);
迁移后的代码:
final ThemeData theme = ThemeData();
MaterialApp(
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(secondary: myColor),
),
//...
)
所以我做了这个改变:
Widget build(BuildContext context) {
+ final ThemeData theme = ThemeData();
return MaterialApp(
title: 'Title',
- theme: ThemeData(
- primaryColor: Color.fromRGBO(95, 53, 90, 1),
- accentColor: Color.fromRGBO(76, 41, 71, 1)
+ theme: theme.copyWith(
+ colorScheme: theme.colorScheme.copyWith(
+ primary: Color.fromRGBO(95, 53, 90, 1),
+ secondary: Color.fromRGBO(76, 41, 71, 1),
),
+ ),
home: MyApp()
);
}
但是现在我的复选框和开关已经从我的原色变成了蓝色。
我还能在主题中设置复选框的颜色吗?
【问题讨论】:
-
这个答案可以帮助你。 stackoverflow.com/questions/69289005/…