如何在抖动中更改框阴影的高度,宽度和不透明度?

时间:2019-06-11 17:40:15

标签: flutter flutter-layout

第一张图像中的按钮具有模糊的阴影,其宽度小于按钮的宽度。

但是当我尝试在我的flutter应用程序中应用该设计时,它看起来就不一样了,而且我也无法设置Ab框阴影的宽度,高度和不透明度。我该怎么办?

app.dart

MaterialButton(
                          onPressed: () {},
                          textColor: Colors.white,
                          padding: const EdgeInsets.all(0.0),
                          child: Container(
                            padding: const EdgeInsets.symmetric(
                                vertical: 4.0, horizontal: 16.0),
                            decoration: BoxDecoration(
                                color: Color(0XFF00D99E),
                                borderRadius: BorderRadius.circular(16.0),
                                boxShadow: [
                                  Opacity(opacity: null),
                                  BoxShadow(
                                    color: Color(0XFF000000),
                                    offset: Offset(0.0, 8.0),
                                    blurRadius: 16.0,
                                  )
                                ]),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.all(4.0),
                                  child: Image.asset(
                                    'assets/icon-chat-notification.png',
                                    color: Colors.white,
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.all(4.0),
                                  child: Text('CART'),
                                )
                              ],
                            ),
                          ),
                        )

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作,技巧是使用负的spreadRadius,并补偿颜色的模糊/不透明度:

Container(
            width: 88,
            height: 30,
            decoration: BoxDecoration(
                color: Color(0xff00D99E),
                borderRadius: BorderRadius.circular(15),
                boxShadow: [
                  BoxShadow(
                      blurRadius: 8,
                      offset: Offset(0, 15),
                      color: Color(0xff00D99E).withOpacity(.6),
                      spreadRadius: -9)
                ]),

////相关代码是BoxShadow()

            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(
                  Icons.shopping_cart,
                  size: 12,
                ),
                SizedBox(width: 6),
                Text("CART",
                    style: TextStyle(
                      fontSize: 10,
                      color: Colors.white,
                      letterSpacing: 1,
                    ))
              ],
            ),
          ),

这是结果: It will look like this, pretty similar