提问人:Bahrican Yesil 提问时间:10/31/2023 更新时间:10/31/2023 访问量:18
有没有办法在 Flutter 的 CupertinoAlertDialog 中显示 ListView.builder?
Is there a way to show ListView.builder inside CupertinoAlertDialog in Flutter?
问:
我正在尝试使用 CupertinoAlertDialog 中的 ListView.builder 作为使用 Flutter 的内容。我不想强制其高度达到预定义的值。相反,我希望它从可用区域中占用它所需的最小空间(动态取决于项目计数)。
示例对应的代码部分:
await showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: const Text('LKJASDasd'),
content: ListView.builder(
itemBuilder: (BuildContext context, int i) =>
Text(i.toString())),
actions: const <Widget>[],
));
我尝试的解决方案给出了以下错误:
════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
RenderShrinkWrappingViewport does not support returning intrinsic dimensions.
Calculating the intrinsic dimensions would require instantiating every child of the viewport, which defeats the point of viewports being lazy.
If you are merely trying to shrink-wrap the viewport in the main axis direction, you should be able to achieve that effect by just giving the viewport loose constraints, without needing to measure its intrinsic dimensions.
The relevant error-causing widget was
CupertinoAlertDialog
我尝试将 Column 与 MainAxisSize.min 或 SingleChildScrollView 一起使用,但它们不起作用。由于我不想强制它的高度,因此 SizedBox、ConstrainedBox 或其他小部件对我不起作用。
答: 暂无答案
评论