为什么 SliverFillRemaining 膨胀得太多?

问题描述

我正在尝试制作一个对其高度做出反应的 SliverAppBar,根据它是否展开显示不同的内容

我已经基于 https://medium.com/flutter-community/flutter-sliverappbar-snap-those-headers-544e097248c0,但我遇到了一个问题:

列表末尾的空格太长了。

如果项目数量较多,则不需要移除 SliverFillRemaining,但将 numberOfItems 更改为例如3 个项目(而不是 30 个),SliverFillRemaining 是必要的。

查看此飞镖以获得代码https://dartpad.dev/2c434ddf2d4d1e87bd4b421f0a673c2d

      CustomScrollView(
        physics: AlwaysScrollableScrollPhysics(),controller: _controller,slivers: [
          SliverAppBar(
            pinned: true,backgroundColor: Colors.grey[100],stretch: true,automaticallyImplyLeading: false,flexibleSpace: Header(
              maxHeight: maxHeight,minHeight: minHeight,),collapsedHeight: minimizedHeight,expandedHeight: maxHeight - MediaQuery.of(context).padding.top,SliverList(
            delegate: SliverChildBuilderDelegate(
              (context,index) {
                return _buildCard(index);
              },childCount: numberOfItems,SliverFillRemaining(
              hasScrollBody: true),// ** <-- this will add space,but too much **
        ],

解决方法

如果你只是增加一定高度的空间,我建议你使用 SliverToBoxAdapter:

SliverToBoxAdapter(
  child: SizedBox(
    height: 50,),

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...