填充子容器背景色时,容器阴影消失

时间:2018-12-20 14:16:35

标签: dart flutter

我正在尝试获得带有自定义阴影的材料卡(这就是为什么我不使用卡的高程的原因),当子控制器的颜色设置为白色时,它工作正常,但是阴影消失了(变得很多较弱)时,则子容器中会填充有较深的颜色(如棕色)。

enter image description here enter image description here

这是代码

Container(
      padding: EdgeInsets.only(
        top: 16.0,
        left: 16.0,
        right: 16.0,
      ),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(borderRadius),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.10),
              blurRadius: 8.0,
            ),
          ],
        ),
        child: Card(
          clipBehavior: Clip.antiAlias,
          elevation: 0,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(borderRadius),
          ),
          child: Container(
            /// If this Container is filled then the shadow is gone
            color: Colors.brown,
          ),
        ),
      ),
    );

我什至尝试将CropRRect放在Card或容器上,但不起作用。谁能解释为什么会这样,或者我能做些什么来保持阴影不变?

1 个答案:

答案 0 :(得分:1)

它不会消失,只是一种视觉效果,您可以尝试:

    BoxShadow(
                     color: Colors.black.withOpacity(0.50),
                     blurRadius: 18.0,
                      ),

 color: Colors.brown,