问题描述
在我的应用程序中,目前有一个BottomNavigationBar,其中包含4个项目。它的代码如下:
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(icon: Icon(Icons.home),label: "Startseite"),BottomNavigationBarItem(icon: Icon(Icons.star),label: "Favoriten"),BottomNavigationBarItem(icon: Icon(Icons.casino),label: "Quiz"),BottomNavigationBarItem(icon: Icon(Icons.map),label: "Karte"),],currentIndex: _selectedindex,unselectedItemColor: Colors.grey,showUnselectedLabels: true,selectedItemColor: Colors.blue,onTap: _onItemTapped,),
_selectedindex只是一个整数。 _onItemTapped函数:
void _onItemTapped(int index) {
setState(() {
_selectedindex = index;
});
setState(() {
if (index == 0) {
SwipePage();
} else if (index == 1) {
DatabaseProvider.db.queryDb();
Navigator.of(context).push(
toFavouritesPage(),);
} else if (index == 2) {
Navigator.of(context).push(
toQuizPage(),);
} else if (index == 3) {
Navigator.of(context).push(
toMapsPage(),);
}
});
}
我如何摆脱填充物,使所有东西保持均匀间隔?
解决方法
将bottomNavigationBarType:设置为固定。默认情况下,四个或更多项目正在转移。这将通过使所选项目更加突出来突出显示所选项目。