Error Failed assertion: line 1785 pos 12:’hasSize’
The reason
- SingleChildScrollView nested ListView, GridView report errors, SingleChildScrollView and ListView have scrolling. The properties of physics are all scrollable by default.
- SingleChildScrollView added Expanded or Flexiblez.
Solution
Just add shrinkWrap: true and 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,
)
],
),
)
Fix the height of the parent component
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!'),
),
],
),
)
)