报错 :Failed assertion: line 1785 pos 12: 'hasSize'
原因:1. SingleChildScrollView 嵌套 ListView、GridView报错 ,SingleChildScrollView 和 ListView 都有滚动
属性physics 他们默认是都是可以滚动的
2. SingleChildScrollView 添加了Expanded或者Flexible
解决方法: 1. 增加shrinkWrap: true 和 physics: NeverScrollableScrollPhysics()即可。
SingleChildScrollView(
child: Column(
children: <Widget>[
GridView.count(
crossAxisCount: 2,
children: <Widget>[],
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
),
ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Text("test");
},
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
)
],
),
)
2.固定父级组件的高度
SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Text('Hello World!'),
),
],
),
)
)