垂直视口错误。即使使用收缩包装或扩展也无法修复

问题描述 投票:0回答:1

这是我的代码

 ListView.builder(
          itemCount: customerList.length,
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              child: Expanded(
                child: ListTile(
                  title: Text(customerList[index].customerName),
                  subtitle: Column(
                    children: [
                      Text(customerList[index].customerID),
                      Text(customerList[index].customerAddress),
                    ],
                  ),
                ),
              ),
            );
          }),

我已经使用了收缩包裹和滚动方向,并且我已经尝试摆脱展开的小部件,但我仍然收到此错误

这里是调试控制台

The following assertion was thrown during performLayout():
Vertical viewport was given unbounded width.
Viewports expand in the cross axis to fill their container and constrain their children to match their extent in the cross axis. In this case, a vertical shrinkwrapping viewport was given an unlimited amount of horizontal space in which to expand.

RenderBox was not laid out: RenderShrinkWrappingViewport#90e43 relayoutBoundary=up23 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1972 pos 12: 'hasSize'
flutter flutter-dependencies
1个回答
0
投票

您无法在

ListView
内扩展。

简单来说:

ListView
提供无限的空间,而
Expanded
分配所有可用空间
,所以他们正在朝着相反的目标工作。

© www.soinside.com 2019 - 2024. All rights reserved.