在 CustomScrollView 的末尾对齐小部件,但在屏幕太小时使其可滚动

问题描述 投票:0回答:1

如何使用 CustomScrollView 构建布局,使得底部块:

  1. 当屏幕较小且视图可滚动时与其他 Sliver 保持一致
  2. 当屏幕足够大时与底部边缘对齐,但视图不可滚动

不想使用 LayoutBuilder,因为块的内容可能会有所不同,例如取决于字体大小、显示的内容等。

此外,内容可能会显示在模态底部表单中,因此在包裹整个 CustomScrollView 的可滚动环境中。我们可以访问模态底部表单的控制器。

preview of the layout

飞镖板示例

CustomScrollView(
  slivers: [
    SliverToBoxAdapter(
      child: Container(
        height: 100,
        color: Colors.blue,
      ),
    ),
    SliverToBoxAdapter(
      child: Container(
        height: 300,
        color: Colors.green,
      ),
    ),
    SliverToBoxAdapter(
      child: Container(
        height: 300,
        color: Colors.orange,
        child: Center(
          child: Text(
              'Keep me either aligned to the bottom or in-line with other slivers'),
        ),
      ),
    ),
  ],
),
flutter
1个回答
0
投票

不确定是否可以在 CustomScrollView 中实现这一目标。
这是一个可能有帮助的解决方法

CustomScrollView(
    slivers: [
      SliverToBoxAdapter(
        child: Container(
          height: 100,
          color: Colors.blue,
        ),
      ),
      SliverToBoxAdapter(
        child: Container(
          height: 300,
          color: Colors.green,
        ),
      ),
      SliverFillRemaining(
        child: Container(
          height: 300,
          color: Colors.orange,
          child: Center(
            child: Text(
                'Keep me either aligned to the bottom or in-line with other slivers'),
          ),
        ),
      )
    ],
  )
© www.soinside.com 2019 - 2024. All rights reserved.