Page doesnot scroll when nesting ListView in flutter
I have a ListView(2) nested inside another ListView(1).
Whenever I replace 2 with a container, the whole page scrolls fine but as soon as I enable both list views inside each other, both stop scrolling.
This is the main ListView implementation
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(20.0),
child: ListView(
primary: true, //does not have any effect
physics: const AlwaysScrollableScrollPhysics(),
children: [
Container( ...etc.
And this is the second listview implementation inside the first listview:
Expanded(
child: ListView(
primary: false,
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
),
);
Expanded
cannot be used in a ListView
Try this using SizedBox
and setting the height to a desire number
If you want the ListView(2) to take the entire screen (and more) try this:
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: [
Container(
color: Colors.pink,
width: 400,
height: 800
),
SizedBox(
height: MediaQuery.of(context).size.height,
child: ListView(
children: List.generate(300, (i) => Text(i.toString()))
),
)
]
)
);
}