我正在尝试在 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/