简体   繁体   English

Flutter 嵌套 Row 和 ListView 的扩展高度

[英]Flutter expanded height in nested Row and ListView

卡片样本

I have a Card inside a ListView which should be like the picture above.我在 ListView 中有一张卡片,它应该像上图一样。

//Code has been simplified by removing most theme.
ListView(
          children: [
            Card(
              child: Row(children: [
                Container(
                  color: Colors.red,
                  width: 8,
                  height: double.infinity, //Promblem here!!!
                ),
                SizedBox(width: 8),
                Expanded(
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text(
                        'Detail',
                      ),
                      Text('Detail'),
                      SizedBox(
                        width: double.infinity,
                        child: Text(
                          DateTime.now().toString(),
                          textAlign: TextAlign.end,
                        ),
                      ),
                    ],
                  ),
                )
              ]),
            ),
          ]),

The problem is the Container with red color.问题是红色的容器。 It's a red vertical line as a notification thing.这是一条红色的垂直线作为通知。 I want it to as high as Row or Card, but keep a limited width like 4.我希望它与 Row 或 Card 一样高,但保持有限的宽度,如 4。

So I have tried height: double.infinity and Expanded with the Container.所以我尝试了height: double.infinityExpanded with the Container。 It's either an exception or an overflow.它要么是异常,要么是溢出。 And also, trying to wrap the Row with Expanded cause another layout exception.而且,尝试用 Expanded 包装 Row 会导致另一个布局异常。

So how to make this red vertical line have a properly height?那么如何让这条红色竖线有合适的高度呢?

Easy way to Achieve this is:实现这一点的简单方法是:

ListView(
        children: [
          ListTile(
            leading: SizedBox(height: 40, width: 8.0, child: Container(color: Colors.red, width: 6.0,)),
            title: const Text("Random Name"),
            subtitle:  Text("Short Description \n ${DateTime.now()}"),
          ),
          ListTile(
            leading: SizedBox(height: 40, width: 8.0, child: Container(color: Colors.red, width: 6.0,)),
            title: const Text("Random Name"),
            subtitle:  Text("Short Description \n ${DateTime.now()}"),
          ),
          ListTile(
            leading: SizedBox(height: 40, width: 8.0, child: Container(color: Colors.red, width: 6.0,)),
            title: const Text("Random Name"),
            subtitle:  Text("Short Description \n ${DateTime.now()}"),
          ),ListTile(
            leading: SizedBox(height: 40, width: 8.0, child: Container(color: Colors.red, width: 6.0,)),
            title: const Text("Random Name"),
            subtitle:  Text("Short Description \n ${DateTime.now()}"),
          ),

        ],
      ),

在此处输入图像描述

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

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