gpt4 book ai didi

flutter - 如何在 SliverAppBar 底部添加一个 Button 并使其在 ExtentList 上重叠?

转载 作者:行者123 更新时间:2023-12-04 02:41:03 27 4
gpt4 key购买 nike

我尝试在 SliverAppBar 底部属性中放置一个 Column(a Container inside) 作为按钮,但它不能与 ExtentList 重叠,只是溢出底部边距。
我想让它像 Spotify App 一样重叠。

这是 Spotify 示例:
https://imgur.com/VrZRY4c

这是我试过的:
https://imgur.com/4bNZw8j

我的代码:

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
),
],
),
);
}
}

关于flutter - 如何在 SliverAppBar 底部添加一个 Button 并使其在 ExtentList 上重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59403258/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com