问题描述:
我已经定义了一个保存颜色值的变量,当我设置屏幕时,我总是改变这个颜色。我想在我的应用程序中将这种颜色用作普通颜色和 shade100。但是,我的代码在下面给出了错误。
- late Color objeColor;
- objeColor = Colors.orange;
-
- Container(
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: objeColor, // there is no error *******
- ),),
-
-
- Container(
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: objeColor.shade100, // there is error *******
- ),),
错误:
The getter 'shade100' isn't defined for the type 'Color'. Try importing the library that defines 'shade100', correcting the name to the name of an existing getter, or defining a getter or field named 'shade100'
解决思路一:
您不能在小部件树中再次更改颜色的阴影。虽然你有很多其他方法来操纵颜色。例如,objeColor.withAlpha(75)看起来完全一样Colors.orange.shade100,所以它完全符合您的需求。在其他用例中,您可以尝试使用其他方法,例如withOpacity().
解决思路二:
shade100是 MaterialColor. 你可以做
- late MaterialColor objeColor;
- ...
- color: objeColor.shade100
如果您觉得有帮助,可以关注公众号——定期发布有用的资讯和资源