flutter - 如何在颤动的底部导航栏中垂直和水平地在中心添加一个按钮?
问题描述
我尝试了很多不同的方法并在网上寻找解决方案,但找不到任何解决方案。有人可以帮我解决这个问题吗?我希望我的按钮位于底部导航栏的中间,如图 1 所示
解决方案
我要做的是用BottomNavigationBarItem删除/替换FAB(浮动操作按钮)并将其放在BottomNavigationBar的中心并为其创建样式
这是一个例子:
bottomNavigationBar: BottomNavigationBar(
onTap: _selectTab,
showSelectedLabels: false,
showUnselectedLabels: false,
backgroundColor: Theme.of(context).primaryColor,
selectedItemColor: Theme.of(context).accentColor,
unselectedItemColor: Colors.black,
currentIndex: _selectedScreenIndex,
//type: BottomNavigationBarType.shifting,
items: [
BottomNavigationBarItem(
icon: Icon(
Icons.category,
),
label: 'Categories',
),
BottomNavigationBarItem(
icon: Container(
decoration: BoxDecoration(
color: Colors.yellow,
shape: BoxShape.circle,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.add,
),
iconSize: 40,
)
// Icon(
// Icons.add,
// ),
),
),
label: 'Add',
),
BottomNavigationBarItem(
icon: Icon(
Icons.star,
),
label: 'Favorites',
),
],
),
底部导航还有这个替代选项https://pub.dev/packages/convex_bottom_bar
推荐阅读
- flutter - Flutter Webrtc - 3 对等连接
- ios - UICollectionView:将一个单元格拖动/移动到另一个单元格上(无重新排序)
- image-processing - 维纳滤波器的参数估计
- javascript - 多输入 onChange 问题
- oracle - 如何使用 Azure Active Directory 登录自动创建 Oracle Apex 用户?
- amazon-web-services - 更新 Elastic Beanstalk 上已弃用的 php 平台
- sql - 更新/插入在 postgres 触发器功能中不起作用
- python - 下载 xml 文件并将其保存到文本文件中
- python - 将 0001 年 1 月 1 日转换为时间库的时间戳
- nsis - 如何从 NSIS 中的 RCData 资源中读取字符串