我在flutter应用程序中使用了此软件包https://pub.dev/packages/google_nav_bar,当我尝试向按钮添加onPressed函数以重定向到新的UI时,此方法不起作用。就像我只是单击,什么都没有发生,这就是我从软件包中添加到示例代码中的内容
GButton(
icon: Icons.favorite,
text: 'Saved',
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => FavoriteProviders()));
},
),
GButton(
icon: Icons.send,
text: 'Messages',
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (_) => MessageList()));
},
),
],
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
_selectedIndex = index;
});
}),
),
答案 0 :(得分:0)
尝试使用该插件Presistant_bottom_nav_bar。现在,我可以在每个屏幕上使用bottomnavbar 还具有15多种样式的bottomnavbar变体
PersistentTabController _controller =PersistentTabController(initialIndex: 0);
//Screens for each nav items.import Class your Views
List<Widget> _NavScreens() {
return [
FavoriteProviders(),
MessageList(),
Container(color: Colors.green);
Container(color: Colors.red);
Container(color: Colors.yellow);
];
}
List<PersistentBottomNavBarItem> _navBarsItems() {
return [
PersistentBottomNavBarItem(
icon: Icon(Icons.favorite),
title: ("Saved"),
activeColor: CupertinoColors.activeBlue,
inactiveColor: CupertinoColors.systemGrey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.send),
title: ("Messages"),
activeColor: CupertinoColors.activeGreen,
inactiveColor: CupertinoColors.systemGrey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.person_pin),
title: ("Help"),
activeColor: CupertinoColors.systemRed,
inactiveColor: CupertinoColors.systemGrey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.local_activity),
title: ("ProfileScreen"),
activeColor: CupertinoColors.systemIndigo,
inactiveColor: CupertinoColors.systemGrey,
),
PersistentBottomNavBarItem(
icon: Icon(Icons.local_activity),
title: ("Demo"),
activeColor: CupertinoColors.systemIndigo,
inactiveColor: CupertinoColors.systemGrey,
),
];
}
@override
Widget build(BuildContext context) {
return Center(
child: PersistentTabView(
controller: _controller,
screens: _NavScreens(),
items: _navBarsItems(),
confineInSafeArea: true,
backgroundColor: Colors.white,
handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true,
hideNavigationBarWhenKeyboardShows: true,
popAllScreensOnTapOfSelectedTab: true,
navBarStyle: NavBarStyle.style9,
),
);
}