如何解决BackButton和BottomNavigationBar
我想在页面之间进行导航,当我进入设置页面时,我想要一个后退按钮,该按钮可以将我带到主页,对于收藏夹也是如此,在我的页面上还有一个底部导航栏,该导航栏允许您在它们之间导航。我已经尝试过使用Navigator(),但是它迫使我在主页上放置另一个按钮。我不知道我能否说清楚,但我希望你能帮助我。
谢谢!
更新:我已经使用过getX的软件包。
解决方法
如果设置页面不包括底部的应用程序栏,则可以使用Navigator.of(context).pop()
或顶部的应用程序栏并设置automaticallyImplyLeading = true
以显示同时弹出的后退按钮。 / p>
这是我的底部应用程序栏之一的示例,该栏允许在多个页面之间进行平滑导航:
class _MainScreenState extends State<MainScreen> {
int _currentIndex = 0;
final List<Widget> _children = [
Home(),InboxMain(),DashboardMain(),ProfileMain(),FriendsMain()
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],bottomNavigationBar: new Theme(
data: Theme.of(context).copyWith(
canvasColor: Color.fromRGBO(41,34,78,1),),//
child: BottomNavigationBar(
//selectedItemColor: Colors.red,//selectedIconTheme: IconThemeData(color: Colors.red),type: BottomNavigationBarType.fixed,showSelectedLabels: false,showUnselectedLabels: false,backgroundColor: Color.fromRGBO(41,onTap: onTabTapped,currentIndex: _currentIndex,items: [
BottomNavigationBarItem(
icon: _currentIndex == 0
? Icon(Icons.home_outlined,color: Colors.white)
: Icon(
Icons.home_outlined,color: Colors.grey[600],title: Container(
height: 0,)),BottomNavigationBarItem(
icon: _currentIndex == 1
? Icon(
Icons.email_outlined,color: Colors.white,)
: Icon(
Icons.email_outlined,BottomNavigationBarItem(
icon: _currentIndex == 2
? Icon(Icons.dashboard,color: Colors.white)
: Icon(Icons.dashboard,color: Colors.grey[600]),BottomNavigationBarItem(
icon: _currentIndex == 3
? Icon(
Icons.person,)
: Icon(Icons.person,BottomNavigationBarItem(
icon: _currentIndex == 4
? Icon(
Icons.people_alt,)
: Icon(Icons.people_alt,],);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
我的应用程序(登录后)导航至此,所有导航均在此处进行控制,除了扩展屏幕(我使用后退按钮和pop()
)之外。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。