gpt4 book ai didi

flutter - "theme: ThemeData..."显然从 Flutter 2.5.0 开始被忽略

转载 作者:行者123 更新时间:2023-12-04 17:12:55 27 4
gpt4 key购买 nike

我正在研究来自 flutter.dev 的 startup_namer 教程示例。以下是 MyApp 的定义:

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Startup Name Generator',
theme: ThemeData(
// Add the 3 lines from here...
primaryColor: Colors.white,
), // ... to here.
home: RandomWords());
}
}

过去,当我运行应用程序时,标题栏会是白色的。但现在,它保留了默认(蓝色)主题。看起来 ThemeData 或至少 primaryColor 被忽略了。有谁知道如何解决这一问题?谢谢。

最佳答案

检查这个 link以及来自 Flutter 团队的这句话:

The ThemeData accentColor, accentColorBrightness, accentIconTheme andaccentTextTheme properties have been deprecated.

The Material Design spec no longer specifies or uses an “accent” colorfor the Material components. The default values for component colorsare derived from the overall theme’s color scheme. The ColorScheme’ssecondary color is now typically used instead of accentColor and theonSecondary color is used when a contrasting color is needed.

另请查看迁移指南。

关于您的 appBar 问题,请在 ThemeData() 中执行此操作:

  appBarTheme: AppBarTheme(backgroundColor: Colors.white),

关于flutter - "theme: ThemeData..."显然从 Flutter 2.5.0 开始被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69140787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com