简体   繁体   English

如何为 Flutter 容器提供相当于自己内部孩子和孩子的高度

[英]How to give to a Flutter container the Height equivalent to the child and children inside himself

how it is possible to give to the container height the right height of the equivalent of the total children inside this container?如何给容器高度提供与该容器内所有孩子相等的正确高度? this is my piece of code:这是我的一段代码:


child: Container(
          height: ????,<----HERE TO BE IMPLEMENT HEIGHT
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 15,),
              SearchWidget(),
              Padding(
                padding: const EdgeInsets.fromLTRB(12, 15, 0, 8),
                child: Text('Le offerte del Momento',style: TextStyle(color: Color(0xff494949),fontWeight: FontWeight.w500),),
              ),
              

To get the height of the child use IntrinsicHeight:要获取孩子的高度,请使用 IntrinsicHeight:

Container(
        child: IntrinsicHeight(
                        child: Column(
...

But as it was said in the comments, unless you need some properties of the Container like a decoration for example, you shouldn't use a Container because it is useless in this case.但正如评论中所说,除非您需要 Container 的某些属性,例如装饰,否则不应使用 Container,因为在这种情况下它是无用的。 Just add mainAxisSize: MainAxisSize.min to your column so that its size depends on those of children.只需将mainAxisSize: MainAxisSize.min添加到您的列中,以便其大小取决于孩子的大小。

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

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