gpt4 book ai didi

flutter - 将阴影添加到 ClipRRect

转载 作者:行者123 更新时间:2023-12-04 13:16:12 25 4
gpt4 key购买 nike

我想为 ClipRRect 添加阴影在 flutter 中。我希望它看起来像这样:

App with shadow

但是当我尝试构建它时,我得到了这样的东西:

enter image description here

阴影穿过整个框而不是 ClipRRect 区域。这是我的代码:

Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Color(0x54000000),
spreadRadius: 10,
blurRadius: 2,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(250)),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
colors: [
Theme.of(context).primaryColor,
Color(0xff995DFF)
])),
height: 500,
width: MediaQuery.of(context).size.width,
),
),
)
],
)

不知何故,阴影需要正好在 ClipRRect 上。谢谢你的帮助

最佳答案

发生这种情况是因为具有 shadown 的容器是一个 rect 作为默认形状...

卖出期权 BorderRadius像这样装饰容器父亲:

        Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
//Here goes the same radius, u can put into a var or function
borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(250)),
boxShadow: [
BoxShadow(
color: Color(0x54000000),
spreadRadius:4,
blurRadius: 20,
),
],
),
child: ClipRRect(
borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(250)),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
colors: [
Theme.of(context).primaryColor,
Color(0xff995DFF)
],
),
),
height: 500,
width: MediaQuery.of(context).size.width,
),
),
)
],
),

关于flutter - 将阴影添加到 ClipRRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60270936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com