dart - Column 内展开的小部件未展开,而是不可见

我正在尝试在 Column 小部件内扩展小部件,但无法使其扩展。

当给父部件固定高度时,布局将按预期呈现。但是当我删除恒定高度时,布局并不像我想用它制作 Listview 的预期那样,我不应该为将用作 ListView 项的小部件提供恒定高度。

下面是我的布局代码。

 import 'package:flutter/material.dart';

 void main() {

 runApp(MaterialApp(
title: 'layout test',
home: Layout_test_class(),
));

 }



class Layout_test_class extends StatelessWidget {

Widget cell() {

return Container(
  color: Colors.yellow,
//      height: 200, after un commenting this will work. but i want to make it without this

  child: Row(
    crossAxisAlignment: CrossAxisAlignment.end,
    mainAxisSize: MainAxisSize.max,
    children: <Widget>[

      Expanded(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[

            Expanded(
              child: Container(
                color: Colors.green,
                child: Text('apple z'),
              ),
            ),

            Container(
              color: Colors.red,
              child:Text('apple 2'),
            )
          ],
        ),
      ),

      Column(
        children: <Widget>[
          Container(
            color: Colors.black,
            width: 200,
            height: 200,
          ),
        ],
      ),

    ],
  ),

);

}

@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
  appBar: AppBar(
    title: Text('title'),
  ),
  body: Center(
   child: ListView(
     children: <Widget>[
       cell(),
     ],
   )
  ),
);
}

}

以下是我预期的输出屏幕截图。

最佳答案

尝试用 IntrinsicHeight 包裹您的容器

return IntrinsicHeight(
        Container(
          color: Colors.yellow
          child: ...
        )
)

https://stackoverflow.com/questions/54493197/

相关文章:

dart - Dart 类中带下划线的命名参数

dart - Flutter如何将容器背景设置为透明色

dart - Flutter - 遍历对象键和值

dart - Flutter,如何让我的原 Material 纽扣更大更紧密地组合在一起。

dart - 向 Flutter 中的计算函数发送多个参数

github - 如何在 Flutter 中添加来自 GitHub 的包?

dart - 我们可以使用 Flutter 或 Dart 制作 Web 应用程序或网站吗

forms - 如何从另一个屏幕重置 Flutter 中的表单?

dart - Flutter getter 没有为类指定,当它被指定时

flutter - 标题在flexibleSpaceBar上没有正确显示