[英]ListView rendering error on GetX's Get.defaultDialog and Get.dialog
If we use Flutter's default AlertDialog and showDialog, we don't encounter any issues with the ListView wrap.如果我们使用 Flutter 默认的 AlertDialog 和 showDialog,我们不会遇到 ListView 换行的任何问题。
return AlertDialog(
title: Text("Title of Dialog"),
content: SizedBox(
width: double.minPositive,
child: ListView.builder(
shrinkWrap: true,
...
itemBuilder: (BuildContext context, int index) {
...
},
),
),
);
The problem comes when we use Dialog from GetX , are Get.defaultDialog or Get.dialog .当我们使用GetX的 Dialog 时,问题就来了,是Get.defaultDialog或Get.dialog 。 While debugging, an error message appears: "Cannot hit test a render box with no size.'
调试时,会出现一条错误消息: “无法命中测试没有大小的渲染框。” The error can be removed by adding a size height and width for example:
可以通过添加尺寸高度和宽度来消除错误,例如:
content: SizedBox(
width: 300,
heights: 300,
...
)
But the problem is not finished, because a lot of empty space will appear, where the contents of the ListView are smaller than all the widgets in the Dialog.但是问题还没完,因为会出现很多空白,这里ListView的内容比Dialog中的所有widget都小。
I managed to solve the problem using this way:我设法用这种方式解决了问题:
I wrapped the ListView.Builder()
in Flexible
and then I wrapped Flexible
In Column
widget with MainaxisSize
property set to Minimium .我将
ListView.Builder()
包装在Flexible
中,然后包装了Flexible
In Column
小部件, MainaxisSize
属性设置为Minimium 。
Here's the example code you can try:这是您可以尝试的示例代码:
Get.dialog(
Center(
child: Container(
padding: const EdgeInsets.all(20),
width: 200,
color: Colors.amber,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: ListView.builder(
itemCount: 30,
shrinkWrap: true,
itemBuilder: (ctx, index) {
return Center(
child: Text("demo"),
);
},
),
),
],
),
),
),
);
If the itemcount
is less then it will shrink the dialog too.如果
itemcount
数较少,那么它也会缩小对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.