繁体   English   中英

如何为 flutter 中的 sliverList 提供固定高度?

[英]How to give fixed height to a sliverList in flutter?

我正在尝试制作一个在滚动页面时会缩小的可折叠工具栏。

为此,我正在使用 Slivers。 通过使用SliverList ,当数据滚动时,它会在手机屏幕顶部电池和时间透明条中上升。 因此,我想给列表固定高度,以便它在有限的区域内滚动。

在此处输入图像描述

我尝试将SliverList放入SingleChildScrollViewSizedBoxContainer中。 但没有一个奏效。

SliverList(
  delegate: SliverChildBuilderDelegate((context, index) {
    return Container(
      color: Colors.white,
      child: Text("Text"),
    );
  },
  chikdCount:100,
),

您可以使用itemExtend SliverFixedExtentList来更改条子的高度。 从今以后,所有孩子的身高都将与 150.0 相同。 你能检查下面的代码吗?

SafeArea(
   child: CustomScrollView(
    slivers: <Widget>[
      SliverAppBar(
        title: Text('SliverAppBar'),
        backgroundColor: Colors.green,
        expandedHeight: 200.0,
        flexibleSpace: FlexibleSpaceBar(
          background: Image.asset('assets/forest.jpg', fit: BoxFit.cover),
        ),
      ),
      SliverFixedExtentList(
        itemExtent: 150.0,
        delegate: SliverChildListDelegate(
          [
            Container(color: Colors.red),
            Container(color: Colors.purple),
            Container(color: Colors.green),
            Container(color: Colors.orange),
            Container(color: Colors.yellow),
            Container(color: Colors.pink),
          ],
        ),
      ),
    ],
));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM