Flutter 中的primaryColor 和primarySwatch 有什么区别? [英] What is the difference between primaryColor and primarySwatch in Flutter?

查看:171
本文介绍了Flutter 中的primaryColor 和primarySwatch 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Flutter 中,可以使用 ThemeData 类将主题应用于应用程序.但是这个类的两个属性让我感到困惑:primaryColorprimarySwatch.这两个属性之间有什么区别以及何时使用其中一个?谢谢.

In Flutter, one can apply a theme to the app using ThemeData class. But there two propeties of this class that confuses me: primaryColor and primarySwatch. What's the difference between these two properties and when to use one or the other? Thanks.

推荐答案

primarySwatch notColor.它是 MaterialColor.这意味着材质应用将使用不同深浅的颜色.

primarySwatch is not a Color. It's MaterialColor. Which means it's a the different shades of a color a material app will use.

primaryColor 就是其中一种.准确地说,primaryColor 通常等于 primarySwatch[500].

primaryColor is one of those shades. To be exact, primaryColor is normally equal to primarySwatch[500].

通常最好定义一个 primarySwatch 而不是 primaryColor.因为某些材质组件可能会使用 primaryColor 的不同阴影来处理诸如阴影、边框、...

It is usually better to define a primarySwatch instead of primaryColor. Because some material components may use a different shade of the primaryColor for things such as shadow, border, ...

这篇关于Flutter 中的primaryColor 和primarySwatch 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆