[Flutter] ListView 오류 Vertical viewport was given unbounded height.
[Flutter] ListView 오류 Vertical viewport was given unbounded height.
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:
ListView ListView:file:///... ...
ListView 위젯을 하위 위젯으로 사용할 때 이런 오류가 나온다면 SizedBox 위젯으로 감싸준다.
...
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 200,
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 8),
children: widget.products.map((product) {
return ShoppingListItem(product: product, inCart: _shoppingCart.contains(product), onCardChanged: _handleCartChanged);
}).toList(),
),
),
],
),
),
);
}
...