Material Flutter 中的设计主题

Material Design Theme in Flutter

我在哪里设置 https://material.io/resources/color/ 的次要颜色?

根据 ThemeData class 我必须设置 accentColor,我知道该怎么做:"The [accentColor], sometimes called the secondary color".

分析完theme_data.dart还可以设置colorScheme.secondary。但是设置 ColorScheme 的 属性 意味着您必须设置所有属性。您甚至应该设置 ColorScheme 并覆盖它吗?另外,我在哪里设置二次浅色和二次深色?我觉得有点迷茫,因为自定义 ThemeData 的唯一方法是阅读整个 material 主题代码。或者至少是其中的很大一部分。有没有深入的文档?

也许您需要 copyWith 方法,该方法允许您覆盖尽可能少或尽可能多的父 ThemeData。

Where do I set the seconday colors from https://material.io/resources/color/ ?

一般来说,在 ThemeData 中做此操作的好地方可以作为 theme 参数传递给 MaterialApp

But setting a property of ColorScheme means that you have to set all properties

不一定——除非我误解了问题。 ColorScheme 有一个方法 copyWith() 接受一堆命名参数。因此,您可以像这样重用现有的 ColorScheme

final newScehme = someColorScheme.copyWith(background: ...)

当然,诀窍是检索该方案。您可能可以通过访问 ThemeData's colorScheme 属性:

来检索它
Theme.of(context).colorScheme

Are you even supposed to set ColorScheme and override it?

我没有在文档中看到任何反对这样做的建议,尽管我没有梳理所有内容。我想这取决于您的用例。

Also where do I set Secondary Light and Secondary Dark colors?

我不是特别精通 Material 设计指南和复杂性,但也许 secondary and secondaryVariant 是您想要的?

Is there any in depth documentation?

取决于你定义的深入。以下链接提供了与主题和颜色相关的各种属性的合理概述:

另请注意,MaterialApp 上有一个 darkTheme 属性,您可以在系统请求时使用它来指定深色主题。

总的来说,我发现 ThemeData 有很多自定义选项,尤其是当您将它与 copyWith 结合使用时,copyWith 出现在许多与主题相关的 类 中。 ThemeData 是否与 Material 设计指南非常匹配,我不能自信地说。但是,文档确实很好地解释了属性,因此将它们与实际指南进行比较应该可以让人了解什么是什么。