return Scaffold(
body: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(
parent: BouncingScrollPhysics(),
),
controller: controller,
slivers: [
SliverToBoxAdapter(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 64),
child: Text(
'Title',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimary,
),
),
),
),
),
SliverList.builder(
itemCount: tiles.length,
itemBuilder: (context, index) {
final text = tiles[index];
return Card(
margin: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
child: ListTile(
title: Text(
text,
style: theme.textTheme.bodyLarge,
),
),
);
},
),
],
),
);
这会导致我的布局输出在我的手机上如下所示:
我想要的是一种将所有东西都放在中心的方式,如果所有东西都适合屏幕的话,或者继续原样.
有没有可能用Slivers
做类似的事情?我想要它们,因为我希望当项目滚动时,标题会随着项目一起反弹和滚动.