我如何在构造函数中调用主题颜色
How can i call theme colour in constructor
var boxDecoration = BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey.shade300,
boxShadow: [
BoxShadow(
blurRadius: 15,
offset: Offset(4, 4),
color: Colors.grey.shade500,
spreadRadius: 1),
BoxShadow(
blurRadius: 15,
offset: Offset(-4, -4),
color: Colors.white,
spreadRadius: 1)
],
);
这是我的容器构造函数,我想根据系统主题改变它的颜色。喜欢深色和浅色主题的不同颜色。
我该怎么做?
在这种情况下我更喜欢使用方法,
BoxDecoration boxDecoration(BuildContext context) => BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).colorScheme.primary,
boxShadow: [...],
);
并像 decoration: boxDecoration(context),
一样使用它
var boxDecoration = BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey.shade300,
boxShadow: [
BoxShadow(
blurRadius: 15,
offset: Offset(4, 4),
color: Colors.grey.shade500,
spreadRadius: 1),
BoxShadow(
blurRadius: 15,
offset: Offset(-4, -4),
color: Colors.white,
spreadRadius: 1)
],
);
这是我的容器构造函数,我想根据系统主题改变它的颜色。喜欢深色和浅色主题的不同颜色。 我该怎么做?
在这种情况下我更喜欢使用方法,
BoxDecoration boxDecoration(BuildContext context) => BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).colorScheme.primary,
boxShadow: [...],
);
并像 decoration: boxDecoration(context),