Flutter 附带了一堆所谓的“sliver”小部件,可用于根据用户的滚动操作实现不同的效果。默认情况下,根据 Material Design 指南 1 实现类似的效果相当容易,其中标题在英雄图像的底部开始相当大,然后当用户在页面上向下滚动时向上动画到顶部。
为了达到这个效果,你可以使用CustomScrollView https://docs.flutter.io/flutter/widgets/CustomScrollView-class.html with a SliverAppBar https://docs.flutter.io/flutter/material/SliverAppBar-class.html顶部和下面的一些其他条子组件,如下所示:
new CustomScrollView(
slivers: <Widget>[
new SliverAppBar(
pinned: true,
expandedHeight: 250.0,
flexibleSpace: new FlexibleSpaceBar(
title: new Text(_shortTitle),
background: new Image.network(_imageUrl),
),
),
new SliverPadding(
padding: new EdgeInsets.all(16.0),
sliver: new SliverList(
delegate: new SliverChildListDelegate([
new Text(_longTitle),
new Text(_body),
new Text(_author),
new Text(_body),
]),
),
),
],
);
1 向下滚动到“带有图像的灵活空间”材料设计 https://material.io/guidelines/patterns/scrolling-techniques.html#scrolling-techniques-behavior指导方针