我有一个带有条子的 CustomScrollView 正在工作,但我没有找到完全隐藏 SliverAppBar 顶部的方法(即,在滚动时,我想隐藏图像和标题,但显示底部):
编辑:如图所示,我想让 SliverAppBar 的底部保持滚动状态。设置“pinned: false”会在滚动时隐藏两者,所以对我不起作用。
甚至在我添加填充之前,我就希望我的标题在折叠时隐藏,如下所示:
现在它正在截断,我真的很想隐藏它。
我看过可以在 NestedScrollView 中隐藏标题的帖子(例如,上面的 gif),但如果可能的话,我想保留我的 CustomScrollView 吗?
这是我的代码:
class QuestionsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final questionsMgr = Provider.of<Questions>(context);
final List<Question> questions = questionsMgr.questions;
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
bottom: PreferredSize(
preferredSize: const Size.fromHeight(0),
child: ChangeNotifierProvider.value(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ScoreText(),
InstructionsText(),
],
),
),
),
),
backgroundColor: questionsMgr.getScoreColor(),
floating: false,
expandedHeight: 225,
pinned: true,
title: Text(
"Checklist",
textAlign: TextAlign.center,
),
forceElevated: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: Image.asset(
"assets/images/PalFM_blue.jpg",
fit: BoxFit.cover,
),
),
),
SliverList(
最佳答案
SliverAppBar(
pinned: true,
floating: false,
bottom: PreferredSize(
preferredSize: Size.fromHeight(0),
child: AppBar(
将 SliverAppBar 的底部属性设置为 PreferredSize 小部件。将此底部小部件的 preferredSize 属性设置为 0 (Size.fromHeight(0)),这样当条子折叠时,条子应用栏的高度将成为应用栏的高度。
关于flutter - 滚动时在 Flutter SliverAppBar 中隐藏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58478000/