在 flutter 2.5 更新后,我的主题数据有点损坏并且不再接受accentColor。我查看了文档,发现它被“重命名”为 colorScheme.secondary。但无论我如何尝试,我都无法让它为我工作。
这是我当前的代码:
class Themes {
static final lightTheme = ThemeData(
accentColor: Palette.orange,
colorScheme: ColorScheme.light(),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Palette.orange,
foregroundColor: Colors.white,
),
scaffoldBackgroundColor: Colors.white,
);
static final darkTheme = ThemeData(
accentColor: Palette.orange,
colorScheme: ColorScheme.dark(),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Palette.orange,
foregroundColor: Colors.white,
),
scaffoldBackgroundColor: Colors.grey[900],
);
}
flutter 2.5 的变化这么多
尝试使用下面的代码希望对您有帮助
theme: ThemeData(
colorScheme: Theme.of(context).colorScheme.copyWith(secondary: Color(accentColor))
),
欲了解更多信息,请查看官方文档here https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties
final ThemeData theme = ThemeData();
MaterialApp(
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(secondary: myColor),
),
//...
)
迁移前的代码:
Color myColor = Theme.of(context).accentColor;
迁移后的代码:
Color myColor = Theme.of(context).colorScheme.secondary;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)