简体   繁体   English

如何在 flutter 上连接 Container 与框阴影之间的空间?

[英]how to connect space between Container with box shadow on flutter?

I had a problem with my project, i'm trying make container with box shadow on bottom.我的项目有问题,我正在尝试制作底部带有盒子阴影的容器。 below that container i want make to new container but they are some separate space between container, i think its because box shadow.在该容器下方我想制作新容器,但它们是容器之间的一些单独空间,我认为它是因为盒子阴影。 so the question is how to make they connect ith no space but the shadow still visible.所以问题是如何让它们连接起来没有空间但阴影仍然可见。 pic图片

here my code:这是我的代码:

    return Scaffold(
      body: SafeArea(
        child: Container(
          child: ListView(
            physics: BouncingScrollPhysics(),
            children: <Widget>[
              Container(
                child: Padding(
                  padding: const EdgeInsets.all(0.0),
                  child: ClipRRect(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.zero,
                      topRight: Radius.zero,
                    ),
                    child: Container(
                      height: 70.0,
                      margin: const EdgeInsets.only(
                          bottom: 6.0), //Same as `blurRadius` i guess
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(5.5),
                          bottomRight: Radius.circular(5.5),
                          topLeft: Radius.zero,
                          topRight: Radius.zero,
                        ),
                        color: kDarkGreenColor,
                        boxShadow: [
                          BoxShadow(
                            color: Colors.grey,
                            offset: Offset(0.0, 1.0), //(x,y)
                            blurRadius: 6.0,
                          ),
                        ],
                      ),
                      child: ListView.builder(
                          padding: EdgeInsets.only(left: 10, right: 5),
                          itemCount: planticos.length,
                          physics: BouncingScrollPhysics(),
                          scrollDirection: Axis.horizontal,
                          itemBuilder: (context, index) {
                            return Container(
                              margin: EdgeInsets.only(right: 15, bottom: 6),
                              height: 40,
                              width: 70,
                              decoration: BoxDecoration(
                                color: kMainColor.withOpacity(0),
                                image: DecorationImage(
                                  image: AssetImage(planticos[index].image),
                                ),
                              ),
                            );
                          }),
                    ),
                  ),
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 0),
                height: 200,
                color: kMainColor,
              ),
            ],
          ),
        ),
      ),
    );
}

use stack .使用堆栈

2nd Container will be visible over 1st Container . 2nd Container将在1st Container上可见。 for example...例如...

    Stack(
        children: <Widget>[
          Container(
            height: 400,
            decoration: BoxDecoration(
              color: Colors.green,
            ),
          ),
          Container(
            height: 200,
            decoration: BoxDecoration(
              color: Colors.green,
              boxShadow: [
                BoxShadow(
                  color: Colors.red,
                  offset: Offset(0.0, 1.0), //(x,y)
                  blurRadius: 6.0,
                ),
              ],
            ),
          ),
        ],
      ),

在此处输入图像描述

You should use the stack widget, see this example:您应该使用堆栈小部件,请参见以下示例:

Stack(
  children:[
    Container() //which you wanna be under the shadow.
    Container() //which you wanna make it's shadow visible.
  ]
)

Tip: Use Positioned() under the stack to specify the position of containers.提示:使用栈下的 Positioned() 来指定容器的 position。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM