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),
),
]),
),
],
),
);
}
}
Flutter: SliverAppBar 应用程序栏与滚动视图集成,以便它可以根据滚动偏移量在高度上变化