这是我此刻的代码:
ClipRRect(
borderRadius: BorderRadius.circular(11),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: FractionalOffset.bottomLeft,
end: FractionalOffset.topRight,
colors: <Color>[Colors.purple, AppBaseColors.orange],
),
boxShadow: [BoxShadow(color: Colors.yellow)]
),
child: Material(
child: InkWell(
onTap: () {
print("tapped");
},
child: Container(
width: ButtonTheme.of(context).minWidth,
height: ButtonTheme.of(context).height,
child: Center(
child: Text(
"log in",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
),
color: Colors.transparent,
),
),
),
我尝试了什么:
- 在第一个Container中添加boxShadow
- 在第二个Container中添加boxShadow
- 添加另一个带有 boxShadow 的 Container 作为 ClipRRect 的父级
- 在 Material 中添加 boxShadow 作为 shadowColor(ofc 不起作用,因为我没有任何类型的阴影)
- 在上述所有情况下还添加了 spreadRadius 和 blurRadius,但没有任何改变。
知道我做错了什么吗?
最佳答案
您需要进行这些更改:
- 删除
ClipRRect
小部件。 - 在
BoxDecoration
中添加borderRadius
。 向您的
BoxShadow
添加一个Offset
。Container( decoration: BoxDecoration( color: Colors.blue, gradient: LinearGradient( begin: FractionalOffset.bottomLeft, end: FractionalOffset.topRight, colors: <Color>[Colors.purple, Colors.orange], ), borderRadius: BorderRadius.circular(11), boxShadow: [ BoxShadow(color: Colors.yellow, offset: Offset(5.0, 5.0)) ]), child: Material( borderRadius: BorderRadius.circular(11), clipBehavior: Clip.hardEdge, child: InkWell( onTap: () { print("tapped"); }, child: Container( width: ButtonTheme.of(context).minWidth, height: ButtonTheme.of(context).height, child: Center( child: Text( "log in", style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold), ), ), ), ), color: Colors.transparent, ), ),
关于android - Flutter Container BoxShadow 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55955383/