Column안에 여러 개의 ListView.builder를 사용해보려 하였더니, 아래와 같은 오류가 발생했다.
FlutterError (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.)
ListView.builder의 높이를 알 수 없어서 발생하는 오류였다.
위 오류를 해결 할 수 있는 방법 3가지가 있다.
return ListView.builder(
shrinkWrap: true,
itemCount: 3,
itemBuilder: ((context, index) {
return Text('1111');
}));
return SizedBox(
height: 200,
child: ListView.builder(
shrinkWrap: true,
itemCount: 3,
itemBuilder: ((context, index) {
return Text('1111');
}),
),
);
return Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: 3,
itemBuilder: ((context, index) {
return Text('1111');
}),
),
);
참고 문서 : https://terry1213.github.io/flutter/flutter-vertical-viewport-was-given-unbounded-height/