Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  @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(),
    ),
  );

>Solution :

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()))
            ),
          )
        ]
      )
    );
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading