【发布时间】:2020-07-07 05:53:34
【问题描述】:
我真的很喜欢使用 Slivers,但是 SliverAppBar 确实有一个问题: 通常,我使用 SliverAppBar 小部件来创建一个具有视差效果的背景图像的 AppBar。所以我所使用的只是灵活的空间,不幸的是,每当你向下滚动时,它就会被 AppBar 部分挡住。 我尝试通过将颜色值设置为透明来使 AppBar 部分透明,但它所做的只是使整个东西,包括灵活空间,透明..
有没有办法在向下滚动时只使用 SliverAppBar 的灵活空间而不在 AppBar 部分中消失?
这是我使用的代码:
SliverAppBar(
expandedHeight: 220,
pinned: false,
forceElevated: true,
backgroundColor: Colors.transparent,
stretch: true,
leading: Container(),
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background:Stack(
children: <Widget>[
Image(
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
image: AssetImage('assets/images/image2.png'),
),
Positioned(
bottom: 0,
child: Container(
height: 110,
width: MediaQuery.of(context).size.width,
color: Colors.grey,
),
),
Positioned(
bottom: 10,
left: 10,
child: CircleAvatar(
radius: 45,
backgroundImage: AssetImage('assets/images/image.png'),
),
),
Positioned(
bottom: 77,
left: 110,
child: Container(
width: MediaQuery.of(context).size.width -110 -60,
child: Text(
'Name...',
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontSize: 20,
color: Colors.white
),
),
),
),
Positioned(
bottom: 63,
left: 110,
child: Container(
width: MediaQuery.of(context).size.width -110 -60,
child: Text(
'description...',
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontSize: 14,
color: Colors.white70
),
),
),
),
Positioned(
bottom: 5,
left: 110,
child: Container(
width: MediaQuery.of(context).size.width-110,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
],
),
),
),
],
),
),
),
希望这些图片有助于解释我的问题: 弹性空间如下:Image 1 但是一旦向下滚动,灵活的空间就会消失,如图所示:Image 2 我不想让灵活空间消失。
【问题讨论】:
-
你能放下你的代码吗?
-
当然。它使用 2 张图片
-
对不起..但是你能放一个你想要实现的剪辑吗?我无法理解你的解释
-
刚刚添加了 2 张足以说明问题的图片。
标签: flutter flutter-sliver sliverappbar