代码之家  ›  专栏  ›  技术社区  ›  carlosManta

在Flutter中堆叠两个容器

  •  0
  • carlosManta  · 技术社区  · 1 年前

    我正在尝试将容器B堆叠在容器A上,就像下图中一样,但在我的情况下它不起作用,这一定是定位小部件时出错了。

    My code:
    body: Stack(
            children: [
              Column(
                children: [
                  Container(
                    //this contains content of container A with a width of maxFinite and height of 300.
                  ),
    //here comes the 2nd container that i want to stack over first one like in picture.
                  Positioned(
                    top: 50,
                    bottom: 0,
                    left: 0,
                    right: 0,
                    child: Container(
                      width: double.maxFinite,
                      height: 500,
                      decoration: BoxDecoration(
                        color: Colors.yellow,
                        borderRadius: BorderRadius.only(topLeft: Radius.circular(25.0), topRight: Radius.circular(25.0)),
                      ),
                    ),
                  ),
                ],
              ),
          ],
          ),
    

    enter image description here

    如果有人能指引我,谢谢。

    1 回复  |  直到 1 年前
        1
  •  1
  •   Elle Bishop    1 年前

    按以下步骤操作:

    enter image description here

    body: Column
    children: [
    Stack(
    //Container A comes here
    //Container B comes here wrapped with positioned and top:260, i have set the color to white
    ),
    Container(
    //give it the same color as to Container B and give it max height, and add your rest code here),
    ],