【发布时间】:2021-04-06 08:27:15
【问题描述】:
我有一个用于创建渐变效果的小部件:
class GradientContainer extends StatelessWidget {
final child;
GradientContainer({@required this.child});
@override
Widget build(BuildContext context) {
return Stack(children: [
Positioned(
left: 5,
top: 17,
bottom: 5,
right: 9,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.0,
1.0
],
colors: [
Colors.black.withOpacity(0.0),
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.8),
])),
),
)),
child,
]);
}
}
这很有效,直到用户切换到深色主题并且无法非常清晰地隐藏渐变。所以,我想做类似Theme.of(context).scaffoldBackgroundColor.invertColor().withOpacity(0.8) 这样的事情,这样我就可以获得身体的反转颜色,这让我可以在渐变上创建一个很好的对比,无论主题如何。有人知道怎么做吗?我曾尝试在网上查找,但我只能找到如何在图像上应用反转滤镜。
【问题讨论】: