扑。如何将行的第一个孩子扩展为listview高度作为第二个孩子? [英] Flutter. How to expand first child of row to listview height as second child?

查看:59
本文介绍了扑。如何将行的第一个孩子扩展为listview高度作为第二个孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的示例代码:

  Row(
      children: <Widget>[
        Container(
          color: Colors.red,
          child: Text('text'),
        ),
        Expanded(
          child: Container(
            color: Colors.green,
            child: ListView(
              shrinkWrap: true,
              children: <Widget>[
                ListTile(
                  title: Text('Title1'),
                ),
                ListTile(
                  title: Text('Title2'),
                )
              ],
            ),
          ),
        )
      ],
    )

如何将第一个Container扩展到Listview的高度?我尝试了IntrinsicHeight,但不适用于listview。

How to expand first Container to Listview height? I tried IntrinsicHeight, but it do not works with listview.

推荐答案

更简单的方法是将 Listview 更改为&用 SingleChildScrollView 包裹它,然后用 IntrinsicHeight

Much simpler way would be to change Listview to Column & wrap it with SingleChildScrollView then wrap Row with IntrinsicHeight

代码:

body: IntrinsicHeight(
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        Container(
          color: Colors.red,
          child: Text('text'),
        ),
        Flexible(
          child: Container(
            color: Colors.green,
            child: SingleChildScrollView(
              child: Column(
                //   shrinkWrap: true,
                children: <Widget>[
                  ListTile(
                    title: Text('Title1'),
                  ),
                  ListTile(
                    title: Text('Title2'),
                  ),
                  ListTile(
                    title: Text('Title1'),
                  ),
                  ListTile(
                    title: Text('Title2'),
                  ),
                  ListTile(
                    title: Text('Title1'),
                  ),
                ],
              ),
            ),
          ),
        )
      ],
    ),
  ),

这篇关于扑。如何将行的第一个孩子扩展为listview高度作为第二个孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆