dart - 将 SliverFillRemaining 与 CustomScrollView 和

我正在尝试创建一个可以在滚动列表底部有页脚的滚动列表。如果列表没有填满所有的垂直屏幕空间,页脚将需要向下移动到页面底部。

我尝试在 CustomScrollView 中使用 SliverListSliverFillRemaining 来实现此功能,但 SliverFillRemaining 显示了一些意外行为我相信。它占用了比需要更多的空间(参见 gif)。

我使用以下代码创建了这个列表:

child: new CustomScrollView(
  slivers: <Widget>[
    new SliverList(
      delegate: new SliverChildBuilderDelegate(
        (BuildContext context, int index) {
          return new Card(
            child: new Container(
              padding: new EdgeInsets.all(20.0),
              child: new Center(child: new Text("Card $index")),
            ),
          );
        },
        childCount: 3,
      ),
    ),
    new SliverPadding(
      padding: new EdgeInsets.all(5.0),
    ),
    new SliverFillRemaining(
      child: new Container(
        color: Colors.red,
      ),
    )
  ],
)

最佳答案

对于任何正在寻找这个问题的答案的人,我有一个解决方案,只要我需要类似的东西,它就可以很好地工作。

这就是我的管理方式:

class ScrollOrFitBottom extends StatelessWidget {
  final Widget scrollableContent;
  final Widget bottomContent;

  ScrollOrFitBottom({this.scrollableContent, this.bottomContent});

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: <Widget>[
        SliverFillRemaining(
          hasScrollBody: false,
          child: Column(
            children: <Widget>[
              Expanded(child: scrollableContent),
              bottomContent
            ],
          ),
        ),
      ],
    );
  }
}

顾名思义,如果内容太多,它会滚动,否则将某些东西推到底部。

我认为这很简单且不言自明,但如果您有任何问题,请告诉我

示例:https://codepen.io/lazarohcm/pen/xxdWJxb

关于dart - 将 SliverFillRemaining 与 CustomScrollView 和 SliverList 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49602695/

相关文章:

security - Flutter - 如何隐藏或更改小部件,如最近使用的应用程序概述中所示

dart - 如何使用 Flutter 制作可滚动的包装 View ?

android - RenderCustomMultiChildLayoutBox 对象在布局期间被

android - 检索 ro.product.cpu.abi 的设备属性时出错 :

dart - 蒙版/裁剪图像

dart - 如何在 flutter 中实现字母滚动

dart - 如何在每个特定页面上添加文本?

ios - 如何在flutter插件中导入外部iOS框架?

flutter - 文件选择器插件

android - flutter 等效于 `View::onAttachedToWindow` 和