Flutter教学flutter

Flutter(71):Sliver组件之SliverAppBa

2020-10-27  本文已影响0人  starryxp

Flutter教学目录持续更新中

Github源代码持续更新中

1.SliverAppBar介绍

一个Material Design App Bar,跟AppBar差不多,但是支持滚动折叠的效果
这里我们将只介绍SliverAppBar比AppBar多处的属性,基础属性将不再介绍,需要了解基础属性的可以看一下之前的文章:Flutter(11):基础组件之AppBar

2.SliverAppBar属性

3.FlexibleSpaceBar属性

4.CollapseMode属性

5.StretchMode属性

6.使用

  _myOnStretchTrigger() {
    ToastUtil.showToast('onStretchTrigger');
  }

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      physics: BouncingScrollPhysics(),
      slivers: [
        SliverAppBar(
          title: Text('SliverAppBar'),
          expandedHeight: 250,
          collapsedHeight: 100,
          floating: false,
          pinned: true,
          snap: false,
          stretch: true,
          stretchTriggerOffset: 100,
          onStretchTrigger: () {
            return _myOnStretchTrigger();
          },
          flexibleSpace: FlexibleSpaceBar(
            title: Text('FlexibleSpaceBar title'),
            background: Container(
              decoration: BoxDecoration(
                image: DecorationImage(
                  fit: BoxFit.cover,
                  image: NetworkImage(ImageUrlConstant.imageUrl1),
                ),
              ),
              child: Center(
                child: Text(
                  'FlexibleSpaceBar background content',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            centerTitle: false,
            titlePadding: EdgeInsets.all(0),
            collapseMode: CollapseMode.parallax,
            stretchModes: [
              StretchMode.zoomBackground,
              StretchMode.blurBackground,
              StretchMode.fadeTitle,
            ],
          ),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Container(
                height: 50,
                color: Colors.primaries[(index % 10)],
              );
            },
            childCount: 30,
          ),
        ),
      ],
    );
  }
image.png

下一节:Flutter(72):Sliver组件之SliverList

Flutter(72):Sliver组件之SliverList

Flutter教学目录持续更新中

Github源代码持续更新中

上一篇 下一篇

猜你喜欢

热点阅读