flutter多个可滚动widget嵌套使用报错问题:Viewports expand in the scrolling direction to fill their container

在column里面使用listview,代码和报错如下:
	Widget build(BuildContext context) {
	    return Column(
	      children: <Widget>[
	        ListView.builder(
	          itemCount: todos.length,
	          itemBuilder: (context, index) {
			}
		]);
	}

I/flutter (16497): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (16497): The following assertion was thrown during performResize():
I/flutter (16497): Vertical viewport was given unbounded height.
I/flutter (16497): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter (16497): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (16497): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (16497): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (16497): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (16497): instead. Otherwise, consider using the “shrinkWrap” property (or a ShrinkWrappingViewport) to size
I/flutter (16497): the height of the viewport to the sum of the heights of its children.

这个报错说的问题是多个可滚动widget嵌套使用了,使用拓展小组件包裹住listview 就可以了:

Widget build(BuildContext context) {
    return Column(
	   	children: <Widget>[
	      Expanded(
	        child:ListView.builder(
	          itemCount: todos.length,
	          itemBuilder: (context, index) {
	          }
	        )
	     )
	  ]);

你可能感兴趣的:(flutter)