gpt4 book ai didi

how to adjust container's height based on listview itemCount?(如何根据Listview itemCount调整容器高度?)

转载 作者:bug小助手 更新时间:2023-10-24 20:30:01 26 4
gpt4 key购买 nike



I do have a problem adjust my container's height, I want my container's height to be dependent to it's content. However the container is almost taking up the entire screen(exclude appbar and bottom nav)

我有一个问题,调整我的容器的高度,我希望我的容器的高度取决于它的内容物。然而,容器几乎占据了整个屏幕(不包括应用程序栏和底部导航)


This is the sample snippet I've done.

这是我制作的样本片段。


Padding(
padding: const EdgeInsets.all(12.0),
child: Container(
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Color(0xffDDDDDD),
blurRadius: 6.0,
spreadRadius: 2.0,
offset: Offset(0.0, 0.0),
)
],
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: const Icon(Icons.list),
trailing: const Text(
"GFG",
style: TextStyle(color: Colors.green, fontSize: 15),
),
title: Text("List item $index"));
}),
),
],
),
),
)),

I want my container's bottom in the black line that I've drawn and it should be dynamic if the items are less than 5. How do I do it using container?

我想要我的容器的底部在我画的黑线上,如果物品少于5项,它应该是动态的。我如何使用容器来做到这一点?


TRIED: I tried searching some of it says that I should not putting a height and width and it automatically scale to its content. I would appreciate your help.

试过了:我试过搜索其中的一些内容,说我不应该放高和宽,它会自动缩放到它的内容。如果你能帮忙,我将不胜感激。


enter image description here


更多回答
优秀答案推荐

You can remove Expanded widget and set mainAxisSize.min for Column, set shrinkWrap to true in ListView.builder

您可以移除展开的微件并为列设置mainAxisSize.min,在ListView.Builder中将包络处理设置为真


child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListView.builder(
shrinkWrap: true,
...

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com