gpt4 book ai didi

flutter - 如何在 Flutter 的 SliverAppBar 的 flexibleSpace 中移动 Action 和标题?

转载 作者:IT王子 更新时间:2023-10-29 06:32:34 25 4
gpt4 key购买 nike

我正在尝试在 Flutter 中实现类似的东西。

https://a.imge.to/2019/08/22/mgrjU.png

但目前我还停留在这个问题上。

https://a.imge.to/2019/08/22/mgB62.png

操作按钮固定在 UI 的顶部,不会随文本移动。有什么办法可以让他们在 Sliver 中倒下吗?

我一直无法找到一种方法来向 SliverAppBar 的 flexibleSpace 部分添加操作


SliverAppBar(
floating: false,
pinned: true,
expandedHeight: 150.0,
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
flexibleSpace: const FlexibleSpaceBar(
title: Text("User Status", textAlign: TextAlign.justify,),
titlePadding: EdgeInsets.all(15.0),
),
actions: [
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
);

我希望操作按钮与标题文本一起下降。当用户滚动时,按钮应随标题文本移动。

最佳答案

我不确定你是怎么做到的,试试这个有效的代码。

输出:

enter image description here

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
floating: false,
pinned: true,
expandedHeight: 150.0,
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
flexibleSpace: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
width: 200,
child: FlexibleSpaceBar(title: Text("User Status")),
),
Spacer(),
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
),
),
SliverList(
delegate: SliverChildBuilderDelegate((_, i) {
return ListTile(title: Text("Item ${i}"));
}, childCount: 20),
),
],
),
);
}

关于flutter - 如何在 Flutter 的 SliverAppBar 的 flexibleSpace 中移动 Action 和标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57603960/

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