颤动中的容器

发布于 2025-01-09 05:23:21 字数 1310 浏览 5 评论 0原文

希望你们一切都好。我正在制作一个颤振应用程序。在这个界面中我遇到了问题。我正在制作一个堆栈中的容器和圆形头像。在堆栈中,第一个小部件容器中还有另一个容器。当我将图像设置为内部容器的子项时,它也适用于外部容器。为什么会出现这种情况以及这个问题的解决方案是什么。

Stack(
                  children: [
                    // Container(child:
                    Container(
                      decoration: BoxDecoration(
                          border: Border.all(
                        color: Colors.indigo,
                      )),
                      width: 340,
                      height: 200,
                      child: Container(
                        child: Image.asset(
                          'assets/pic1.jpg',
                          fit: BoxFit.cover,
                        ),
                        width: 340,
                        height: 150,
                        decoration: BoxDecoration(
                            border: Border.all(
                          color: Colors.black,
                        )),
                      ),
                    ),
                    Positioned(
                        bottom: 10,
                        right: 10,
                        child: CircleAvatar(
                          backgroundColor: Colors.grey,
                          radius: 40,
                        ))
                  ],
                )

Hope you all are doing well. I am making a flutter application. In this interface I am having a issue. I am making a container and circle avatar which are in stack. In stack, in first widget container there is also another container. When I set image as a child to inner container it also applied to outer container. Why is this happening and what is the solution of this problem.

Stack(
                  children: [
                    // Container(child:
                    Container(
                      decoration: BoxDecoration(
                          border: Border.all(
                        color: Colors.indigo,
                      )),
                      width: 340,
                      height: 200,
                      child: Container(
                        child: Image.asset(
                          'assets/pic1.jpg',
                          fit: BoxFit.cover,
                        ),
                        width: 340,
                        height: 150,
                        decoration: BoxDecoration(
                            border: Border.all(
                          color: Colors.black,
                        )),
                      ),
                    ),
                    Positioned(
                        bottom: 10,
                        right: 10,
                        child: CircleAvatar(
                          backgroundColor: Colors.grey,
                          radius: 40,
                        ))
                  ],
                )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2025-01-16 05:23:21

我认为您只需要将属性对齐到您的父窗口小部件,否则子窗口小部件将不关心高度和宽度

 Stack(
    children: [
      // Container(child:
      Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(
            border: Border.all(
              color: Colors.indigo,
            )),
        width: 340,
        height: 200,
        child: Container(
          child: Image.asset(
            'assets/pic1.jpg',
            fit: BoxFit.cover,
          ),
          width: 340,
          height: 150,
          decoration: BoxDecoration(
              border: Border.all(
                color: Colors.black,
              )),
        ),
      ),
      Positioned(
          bottom: 10,
          right: 10,
          child: CircleAvatar(
            backgroundColor: Colors.grey,
            radius: 40,
          ))
    ],
  )

您还可以按照下面的文章获取更多信息。
https://www.kindacode.com/article/flutter-sizing-a-container-inside-another-container/#:~:text=To%20size%20a%20Container%20that,expand%20to%20its %20父母的%20约束

I think You just need to Alignment Property to your Parent widget otherwise child widget will not care about height and width

 Stack(
    children: [
      // Container(child:
      Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(
            border: Border.all(
              color: Colors.indigo,
            )),
        width: 340,
        height: 200,
        child: Container(
          child: Image.asset(
            'assets/pic1.jpg',
            fit: BoxFit.cover,
          ),
          width: 340,
          height: 150,
          decoration: BoxDecoration(
              border: Border.all(
                color: Colors.black,
              )),
        ),
      ),
      Positioned(
          bottom: 10,
          right: 10,
          child: CircleAvatar(
            backgroundColor: Colors.grey,
            radius: 40,
          ))
    ],
  )

You can also follow the below article to get more information.
https://www.kindacode.com/article/flutter-sizing-a-container-inside-another-container/#:~:text=To%20size%20a%20Container%20that,expand%20to%20its%20parent's%20constraints.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文