简体   繁体   中英

Can Flutter's PageView widget be implemented for a just selected section of the screen instead of the entire screen?

Would it be possible to use the PageView widget just for the contents within Expanded widget in the code below? Essentially trying to swipe right for the items only within the Expanded widget instead of the entire screen.

class _MyHomeScreenState extends State<MyHomeScreen> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: Column(
            children: [
              Container(),
              Container(),
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      Container(),
                      Container(),
                      ListView.builder(itemBuilder: itemBuilder),
                    ],
                  ),
                ),
              ),
            ],
          ),
        );
      }
    }

By doing this code below using the PageView widget, I get this error 'Horizontal viewport was given unbounded height' .

class _MyHomeScreenState extends State<MyHomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        children: [
          Container(),
          Container(),
          PageView(
            children: [
              Container(
                child: Expanded(
                  child: SingleChildScrollView(
                    child: Column(
                      children: [
                        Container(),
                        Container(),
                        ListView.builder(itemBuilder: itemBuilder),
                      ],
                    ),
                  ),
                ),
              ),
              Container(),
            ],
          ),
        ],
      ),
    );
  }
}

You should wrap the pageview inside expanded. you are using an expanded inside pageview

This should fix the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM