flutter - 为什么 SliverFillRemaining 膨胀得太多了?

我正在尝试制作一个对其高度使用react的 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,
  ),
),

https://stackoverflow.com/questions/67367784/

相关文章:

python - 仅当 "Lossless"时才转换为整数?

python - PyCharm 看不到项目中的文件

javascript - 选择选项后如何取消突出显示选择元素?

powerbi - Multi-Tenancy 场景下如何访问power BI Service

python - 枚举二进制变量值的所有可能组合

c++ - 使用具有非 constexpr 值的 int 模板函数

matlab - 如何使用 matlab 正确绘制矢量线性方程?

git - 如何在 GIT 中查看暂存区中的文件内容?

r - 将字符串拆分为单词并分配给新列

GitHub - 当非默认分支与 main 合并时,PR 链接问题不会关闭