【发布时间】:2021-10-08 23:19:43
【问题描述】:
无论我做什么,我似乎都无法在我的颤振应用程序中调整嵌套容器的高度。它似乎总是继承父 Container 的高度。我在网上阅读的所有内容都说用Center() 包裹内部容器。我试过了,但还是遇到了同样的问题。
final _recommendations = <String>["Embroidery", "Jewelry Making", "Tennis", "Hiking", "Disc Golf"];
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Container(
padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 16.0),
height: 200,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _recommendations.length,
itemBuilder: (context, index) {
return Container(
width: 150,
height: 50,
child: Card(
color: Colors.blue,
child: Center(
child: Text(_recommendations[index])
)
)
);
}
)
)
);
在我看来,ListView 的高度是由其父级 Container 定义的。所以我希望ListView 的高度为200。然后Card 的高度应由其父容器定义,其高度为50。但是Card 的高度为200...
【问题讨论】:
-
尝试用
Expanded或Flexible小部件包装您的父容器,如果这不起作用,那么对 ListView 执行相同操作即可 -
用
Expanded或Flexible包裹不起作用...
标签: flutter dart flutter-layout