底部导航栏按钮不起作用颤振



我的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;
});
}),
),

试试这个插件Presistant_pottom_nav_bar。现在我可以在每个屏幕上使用bottomnavbar也有15种以上风格的底部导航条变体

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,
),
);
}

最新更新