Flutter: SliverAppBar 应用程序栏与滚动视图集成,以便它可以根据滚动偏移量在高度上变化

class _MyHomeState extends State<MyHome> with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            // SliverAppBar高度
            expandedHeight: 200.0,

            // 背景填充
            flexibleSpace: FlexibleSpaceBar(
              background: Image.network(
                'https://s2.ax1x.com/2019/05/08/E6hGEn.md.jpg',
                fit: BoxFit.fill,
              ),
            ),

            // 只要手指向下滑动,就弹出SliverAppBar
            floating: true,

            // title
            title: Text('SliverAppBar'),
          ),
          SliverList(
            delegate: SliverChildListDelegate([
              Container(
                height: 300,
                margin: EdgeInsets.only(bottom: 6.0),
                decoration: BoxDecoration(color: Colors.red),
              ),
              Container(
                height: 300,
                margin: EdgeInsets.only(bottom: 6.0),
                decoration: BoxDecoration(color: Colors.green),
              ),
              Container(
                height: 300,
                margin: EdgeInsets.only(bottom: 6.0),
                decoration: BoxDecoration(color: Colors.blue),
              ),
              Container(
                height: 300,
                margin: EdgeInsets.only(bottom: 6.0),
                decoration: BoxDecoration(color: Colors.purple),
              ),
            ]),
          ),
        ],
      ),
    );
  }
}

See Also:

posted @ 2019-05-25 21:18  Ajanuw  阅读(543)  评论(0编辑  收藏  举报