【发布时间】:2021-04-28 18:23:32
【问题描述】:
我有一个 sliverAppbar 和一个滚动的 sliver 列表。但是,我需要在屏幕底部有一个固定容器,无论滚动位置或屏幕上的其他任何内容如何,它都不会移动,相当于 web CSS 中的position fixed。
我使用SliverToBoxAdapter 和stack 和positioned 小部件来实现此功能,但它会引发错误
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
body: CustomScrollView(
slivers: [
SliverAppBar(
primary: true,
pinned: true,
snap: false,
elevation: 1.0,
backgroundColor: Colors.blueAccent,
floating: false,
expandedHeight: 200.0,
title: Text(
"Title",
style: TextStyle(
// color: Colors.grey[900]
),
),
flexibleSpace: FlexibleSpaceBar(
background: Image.network(
"https://images.pexels.com/photos/20990/pexels-photo-20990.jpeg?auto=compress&cs=tinysrgh=650&w=940",
height: double.infinity,
width: double.infinity,
fit: BoxFit.cover,
),
),
),
SliverList(
delegate: SliverChildListDelegate([
Container(color: Colors.red, height: 150.0),
Container(color: Colors.purple, height: 150.0),
Container(color: Colors.green, height: 150.0),
Container(color: Colors.red, height: 150.0),
Container(color: Colors.purple, height: 150.0),
Container(color: Colors.green, height: 150.0),
])),
SliverToBoxAdapter(
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
height: 80.0,
color: Colors.yellowAccent,
),
),
],
)),
],
),
);
}
【问题讨论】: