这是一种可能的方法:
@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
expandedHeight: height * 0.2,
collapsedHeight: height * 0.075,
flexibleSpace: LayoutBuilder(
builder: (context, constraints) {
double appBarHeight = constraints.biggest.height; //getting AppBar height
bool isExpanded = appBarHeight > height * 0.2; //check if AppBar is expanded
return FlexibleSpaceBar(
titlePadding: EdgeInsets.zero,
centerTitle: true,
title: SizedBox(
height: height * 0.15,
child: Column(
mainAxisAlignment: isExpanded
? MainAxisAlignment.center
: MainAxisAlignment.end,
children: <Widget>[
Container(
padding:
isExpanded ? EdgeInsets.zero : EdgeInsets.all(20),
child: Text(
"Training",
),
),
],
),
),
);
},
),
),
SliverList(
delegate: SliverChildListDelegate.fixed(
List.generate(
50,
(index) => ListTile(
title: Text('Index $index'),
),
),
),
),
],
),
);
输出 :