I have been working with BottomNavigationBar in the flutter, but I am not able to select a Tab programmatically outside of onTap callback of BottomNavigationBar.
The code with onTap callback, which is working:
return new BottomNavigationBar(
items: <BottomNavigationBarItem>[
_bottomNavigationItem(Icons.account_circle, DrawerTitles.CONTACTS),
_bottomNavigationItem(Icons.delete, DrawerTitles.DELETED_CONTACTS),
_bottomNavigationItem(Icons.list, DrawerTitles.LOGS),
],
onTap: (int index) {
setState(() {
navigationIndex = index;
switch (navigationIndex) {
case 0:
handleBottomNavigationBarClicks(DrawerTitles.CONTACTS);
break;
case 1:
handleBottomNavigationBarClicks(DrawerTitles.DELETED_CONTACTS);
break;
case 2:
handleBottomNavigationBarClicks(DrawerTitles.LOGS);
break;
}
});
},
currentIndex: navigationIndex,
fixedColor: Colors.blue[400],
type: BottomNavigationBarType.fixed,
);
But I want to change the tabs outside of onTap callback.
I have tried changing the index used by BottomNavigatioBar outside of onTap callBack, but it didn't work.
Here is what I have tried:
void changeTabs(int tabIndex) {
setState(() {
navigationIndex = tabIndex;
});}
Here is a gist for the code.
Is there any way available to change Tabs?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…