首页 > 解决方案 > Flutter:Container + ListView 可滚动

问题描述

我有一个带有容器 + listView 的页面。现在 listView 是可滚动的,但我希望整个页面都是可滚动的。(所以如果用户滚动,容器就会“离开”)

Column(
        children: <Widget>[
          Container(
              color: Colors.white.withOpacity(0.95),
              width: 400,
              height: 400,
              child: Text("")),
          ListView(
              children: posts,
            ),
        ],
      ),

这可能吗,如何实现?

谢谢!

标签: flutterdart

解决方案


你可以用一个包裹整个页面SingleChildScrollView

这是一个例子:

SingleChildScrollView( // <- added
    child: Column(
        children: <Widget>[
          Container(
              color: Colors.white.withOpacity(0.95),
              width: 400,
              height: 400,
              child: Text("")),
          ListView(
              shrinkWrap: true, // <- added
              primary: false, // <- added
              children: posts,
            ),
        ],
      ),
);

有关查看此问题的更多信息


推荐阅读