如何在 SliverAppBar 的底部添加一个按钮,并使其在扩展范围列表上重叠?



我尝试在SliverAppBar底部属性中放置一个列(内部容器(作为按钮,但它不能与ExtentList重叠,只是溢出了底部边距。 我想让它重叠,就像Spotify App一样。

这是 Spotify 示例: https://i.stack.imgur.com/mdWtS.jpg

这是我尝试过的: https://i.stack.imgur.com/xcCVP.jpg

我的代码:

class _MenuListState extends State<MenuList> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverPadding(
padding: EdgeInsets.only(top: 10, bottom: 10),
sliver: SliverAppBar(
pinned: true,
expandedHeight: 300,
title: Text(
'Testing',
style: TextStyle(color: Colors.red),
),
flexibleSpace: FlexibleSpaceBar(
title: Text(''),
background: Image.asset(
'images/w.jpg',
fit: BoxFit.cover,
),
),
bottom: PreferredSize(
child: Column(children: <Widget>[
Text(
'test',
style: TextStyle(),
),
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(109, 76, 65, 1),
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
height: 54,
width: 100,
),
]),
),
),
),
SliverFixedExtentList(//extentlist)
],
),
);
}
}

试试这个

class _MenuListState extends State<MenuList> {
static const double _appBarBottomBtnPosition =
24.0; //change this value to position your button vertically
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text(
'Testing',
style: TextStyle(color: Colors.red),
),
),
SliverAppBar(
pinned: true,
expandedHeight: 300.0,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
titlePadding: EdgeInsets.only(bottom: 25),
title: Text('Title'),
background: Image.asset(
'images/w.jpg',
fit: BoxFit.cover,
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(0.0),
child: Transform.translate(
offset: const Offset(0, _appBarBottomBtnPosition),
child: RaisedButton(
shape: StadiumBorder(),
child: Text("Click Here"),
onPressed: () {},
),
),
),
),
SliverPadding(
padding: EdgeInsets.only(top: _appBarBottomBtnPosition),
),
SliverFixedExtentList(
//extentlist
),
],
),
);
}
}

@Crazy Lazy Cat提供的答案有效..但是如果您担心使用2个SliverAppBar。 你可以用下面的代码替换 2 个银条应用栏

SliverAppBar(
expandedHeight: 500.0,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset(
'images/w.jpg',
fit: BoxFit.cover,
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(0.0),
child: Transform.translate(
offset: const Offset(0, _appBarBottomBtnPosition),
child: RaisedButton(
shape: StadiumBorder(),
child: Text("Click Here"),
onPressed: () {},
),
),
),
),

最新更新