简体   繁体   English

Flutter:ListTile的尾随孩子们在一起

[英]Flutter: ListTile's trailing children stick together

I am new to flutter. 我是新来的扑扑。 Trying to achieve the infinite ListTile. 试图实现无限的ListTile。 The issue is that the children in trailing(with red background) stick together at the center I want them to stick to the top and bottom end which I tried by using mainAxisAlignment: MainAxisAlignment.spaceBetween but the columns height won't expand even after setting mainAxisSize: MainAxisSize.max . 问题是尾随的孩子(带有红色背景)在中心处粘在一起,我希望他们粘到我通过使用mainAxisAlignment: MainAxisAlignment.spaceBetween尝试过的顶端和底端,但是即使设置后列的高度也不会扩展mainAxisSize: MainAxisSize.max

I have tried adding Expand and Flex widgets, also tried using Row Column structure rather that ListView but still the same issue. 我尝试添加Expand和Flex窗口小部件,还尝试使用行列结构而不是ListView,但仍然存在相同的问题。 Only giving height to trailing column worked but wanted it to work dynamically without giving height. 仅给尾随列提供高度,但希望它动态地工作而不给其高度。 Below are links for the code. 以下是代码的链接。

  1. Image: ListView trailing issue 图片: ListView尾随问题
  2. Code with ListTile widget https://www.pastefile.com/IbImGL 使用ListTile小部件进行编码https://www.pastefile.com/IbImGL
  3. Code with Row Column https://www.pastefile.com/o9JK6 行列代码https://www.pastefile.com/o9JK6

Ok, the easy solution could using a fixed height , you can calculate the value based on the size of your screen using : 好的,简单的解决方案可以使用固定的高度,您可以使用以下方法根据屏幕尺寸计算值:

 MediaQuery.of(context).size.height 

Another solution is using IntrinsicHeight Widget, but be carefully because the description of the Widget says that is very expensive 另一个解决方案是使用IntrinsicHeight Widget,但是要小心,因为Widget的说明说这非常昂贵

        IntrinsicHeight(
                      child: Row(
                        children: [
                          buildLeftSection(),
                          buildMiddleSection(),
                          buildRightSection()
                        ],
                      ),
                    )



    Widget buildRightSection() {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[new Text("Title"), new Text("Title")],
      );
    }

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

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