[英]Flutter height size ListView.Builder in AlertDialog
How to set the size of ListView.Builder?如何设置 ListView.Builder 的大小?
After several searches, my code looks like this:经过几次搜索,我的代码如下所示:
My ListView.builder我的 ListView.builder
ListView.builder(
physics:
const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: listBenefits.length,
,
itemBuilder: (context, i) {
return MyWidget()
});
ListView.builder is wrapped in a column ListView.builder 被包裹在一个列中
Column(
mainAxisSize: MainAxisSize.min,
children: [ListView.builder()]),
My column is wrapped in a container which is also wrapped in a column我的专栏被包裹在一个容器中,该容器也被包裹在一个专栏中
AlertDialog(
elevation: elevationAlertDialog,
shape: shapeCard,
scrollable: true,
content: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: double.maxFinite,
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
borderRadius: const BorderRadius.all(Radius.circular(20.0)),
),
child: Column()),
],
));
My AlertDialog has been called from:我的 AlertDialog 已从以下位置调用:
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: AlertDialog());
},
);
The result is an infinite ListView.builder, whereas I would like it to scale to the size of its children.结果是一个无限的 ListView.builder,而我希望它可以缩放到其子项的大小。 Child size is obviously dynamic !
儿童尺寸显然是动态的!
Anyone have a solution for me?有人对我有解决方案吗?
You can use SizedBox for ListView Builder to set preferred size,您可以使用SizedBox for ListView Builder 设置首选大小,
Example,例子,
Column(
children: [
Container(
child: Text("Some Element Before List View"),
),
SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * .5,
child: ListView.builder(
itemCount: 20,
itemBuilder: (BuildContext cont, int index) {
return ListTile(
title: Text("Test $index"),
);
},
),
),
Container(
child: Text("Some Element After List View"),
),
],
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.