美文网首页Flutter教学
Flutter(75):Sliver组件之SliverFixed

Flutter(75):Sliver组件之SliverFixed

作者: starryxp | 来源:发表于2020-10-29 22:12 被阅读0次

Flutter教学目录持续更新中

Github源代码持续更新中

1.SliverFixedExtentList

可以固定Item高度的SliverList

2.SliverFixedExtentList

  • delegate:SliverChildDelegate
  • itemExtent:item高度

3.使用

这个就是比SliverList多了item高度控制:Flutter(72):Sliver组件之SliverList

这里item内子控件高度是200,但是我们SliverFixedExtentList约束为100,那么item高度就会是100,如果内部高度小于100也一样会强制变为100

  _mySliverAppBar() {
    return SliverAppBar(
      title: Text('SliverFixedExtentList'),
      expandedHeight: 250,
      flexibleSpace: FlexibleSpaceBar(
        background: Image.network(
          ImageUrlConstant.imageUrl1,
          fit: BoxFit.cover,
        ),
        collapseMode: CollapseMode.parallax,
      ),
    );
  }

  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
      (BuildContext context, int index) {
        return Container(
          height: 200,
          color: Colors.primaries[index % 11],
        );
      },
      childCount: 30,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: CustomScrollView(
        slivers: [
          SliverFixedExtentList(
            delegate: _mySliverChildBuilderDelegate(),
            itemExtent: 100,
          ),
        ],
      ),
    );
  }
image.png

下一节:Sliver组件之SliverPrototypeExtentList

Flutter(76):Sliver组件之SliverPrototypeExtentList

Flutter教学目录持续更新中

Github源代码持续更新中

相关文章

网友评论

    本文标题:Flutter(75):Sliver组件之SliverFixed

    本文链接:https://www.haomeiwen.com/subject/henlvktx.html