flutter - 带有 SliverApp 栏的 Home 底部应用栏
问题描述
嗨,伙计们,我正在尝试将底部应用栏放置到 sliverappbar 所在的页面中,但未成功....
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.purple,
pinned: false,
forceElevated: true,
floating: false,
title: Text("iBeautik"),
centerTitle: true,
actions: <Widget>[
IconButton(icon: Icon(Icons.apps), onPressed: () {}),
],
expandedHeight: 160,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: Image.asset(
'assets/images/sliverImage.jpg',
fit: BoxFit.cover,
),
),
),
SliverList(
delegate: SliverChildListDelegate(
[
Container(
color: Colors.purple,
child: ListView.builder(
然后是底部栏..
class _BottomNavState extends State<BottomNav> {
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: navigationDrawer(context),
floatingActionButton: FloatingActionButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
side: BorderSide(color: Color(0xFF1f2032), width: 2)),
splashColor: Color(0xFF1f2032),
backgroundColor: Color(0xfffeaf0d),
child: Icon(
Icons.add,
color: Color(0xFF1f2032),
size: 25,
),
onPressed: () {
}),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked);
}
Widget navigationDrawer(BuildContext context) {
解决方案
您可以将底部栏设置为bottomNavigationBar
的Scaffold
并将 添加SilverAppBar
为 的主体Scaffold
,例如,
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
bottomNavigationBar: BottomAppBar(
child: Container(
height: 70,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
iconSize: 30.0,
icon: Icon(Icons.home),
onPressed: () {
setState(() {});
},
),
IconButton(
iconSize: 30.0,
icon: Icon(Icons.search),
onPressed: () {
setState(() {});
},
),
IconButton(
iconSize: 30.0,
icon: Icon(Icons.add),
onPressed: () {
setState(() {});
},
),
IconButton(
iconSize: 30.0,
icon: Icon(Icons.notifications),
onPressed: () {
setState(() {});
},
),
IconButton(
iconSize: 30.0,
icon: Icon(Icons.list),
onPressed: () {
setState(() {});
},
)
],
),
)),
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxScrolled) {
return <Widget>[
SliverAppBar(
pinned: true,
backgroundColor: Colors.deepPurpleAccent,
title: Text("Silver app bar"),
),
];
},
body: ListView.builder(
itemCount: itemList.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(itemList[index]),
),
);
})),
);
}
}
结果:
推荐阅读
- linux - 编写参数日志、标准输入和标准输出的包装脚本
- python - ImportError:在 MACOS Big Sur 版本 11.4 上没有名为 jenkinsapi.jenkins 的模块
- unity3d - 在世界范围内旋转粒子系统
- html - 在表单中并排堆叠输入字段和标签的最佳方法是什么。(不使其适用于整个表格)
- angular - 在 jwt 中验证信息的问题
- riscv - 如何将图形建模为 c 中的 riscv 自定义指令
- javascript - 如何使用 e.target.value 和 React useState Hooks 传递数字数组?
- django - 如何在 django 表单中设置变量 maxValue
- html - 如何仅将背景颜色属性应用于文本所在的区域?
- python - Discord.py 我想在我的机器人所在的每台服务器上 ping 某个角色