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

How do I put a flutter PageView inside a Listview?

My goal is to have a Pageview horizontal scroll only for some widgets in my Listview. My expectation is, I can just put Pageview inside a Listview, but I got some kind of error unbound height. Which led me to this question, it solves the problem by containing Pageview inside a Container or Sizedbox. The solution did work for Column but doesn’t work for Listview. Still got the same error unbound height.

Here is the code that I write


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView(
          padding: const EdgeInsets.all(24),
          children: [
            SomeWidget(),

            // Dropdown status
            SizedBox(height: 16),
            SomeWidget(),

            // The Pageview
            SizedBox(height: 16),
            Expanded(
              child: PageView(
                children: <Widget>[
                  SizedBox(height: 100, child: Container(color: Colors.red)),
                  Container(color: Colors.blue),
                  Container(color: Colors.yellow),
                  Container(color: Colors.amber),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

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

>Solution :

Page View Requires size Expanded
while list view must know the size of its children
you can use this library
https://pub.dev/packages/expandable_page_view
which is know the size of screen then set it to the WebView

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