티스토리 뷰

[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(),
              ),
            ),
          ],
        ),
      ),
    );
  }
...
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함