颤振需要在图像上添加阴影

时间:2020-05-19 19:19:56

标签: flutter

我需要在图像中添加阴影。只是在图像上而不是我尝试的其他容器上,但是它没有显示阴影

这是我的代码

return Container(
  margin: EdgeInsets.only(left: 40),
  width: MediaQuery.of(context).size.width * 0.5,
  child: ListView.builder(
      itemCount: _places.length,
      itemBuilder: (ctx, int index) {
        return Container(
          padding: EdgeInsets.only(top: 50),
          child: Column(
            children: <Widget>[
              Text(_places[index]['name'], style: TextStyle(fontSize: 20),),
              Container(
                padding: EdgeInsets.only(top: 20),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(20.0),
                  child: Container(
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(10),
                          topRight: Radius.circular(10),
                          bottomLeft: Radius.circular(10),
                          bottomRight: Radius.circular(10)
                      ),
                      boxShadow: [
                        BoxShadow(
                          color: Colors.grey.withOpacity(0.5),
                          spreadRadius: 5,
                          blurRadius: 7,
                          offset: Offset(0, 3), // changes position of shadow
                        ),
                      ],
                    ),
                    width: 200,
                    child: Image(image: AssetImage('assets/images/500place.jpg')),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 7),
                child: Row(
                  children: <Widget>[
                    Icon(Icons.favorite_border, size: 20),
                    Spacer(),
                    Text(
                      _places[index]['where'],
                    ),
                  ],
                )
              ),

            ],
          ),
        );
      }),
);

enter image description here

正如您看到输出屏幕的结果一样,我只需要在图像上显示光影,我在容器中添加了框影,但它仅对图像不起作用

1 个答案:

答案 0 :(得分:0)

Card ..包裹起来,这会给你elevation(阴影)..

您可以这样做。.

Card(
child: Container(),
elevation: 20.0, // give it according to your requirement
),