══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performResize():Vertical viewport was given unbounded height.
Viewports expand in the scrolling direction to fill their container. In this case, a vertical
viewport was given an unlimited amount of vertical space in which to expand. This situation
typically happens when a scrollable widget is nested inside another scrollable widget.
If this widget is always nested in a scrollable widget there is no need to use a viewport because
there will always be enough vertical space for the children. In this case, consider using a Column
or Wrap instead. Otherwise, consider using a CustomScrollView to concatenate arbitrary slivers into
a single scrollable.
The relevant error-causing widget was:
MasonryGridView
根据上面的报错信息,可以看出是 MasonryGridView组件的问题,原来是忘了配置shrinkWrap: true
解决办法:
必须要在 MasonryGridView.count()中配置shrinkWrap属性,让元素的宽度自适应,就可以解决报错问题了。
示例:
MasonryGridView.count(
crossAxisCount: 4,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
itemCount: 20,
shrinkWrap: true,//收缩,让元素宽度自适应
itemBuilder: (context, index) {
return Container(
height: height,
decoration: BoxDecoration(
border: Border.all(color: Colors.black,width: 1),
borderRadius: BorderRadius.circular(10),
),
);
},
)