BackButton 和 BottomNavigationBar

BackButton and BottomNavigationBar

我想在我的页面之间导航,当我在设置页面上时,我想要一个后退按钮,它将我带到主页和收藏夹,我的页面还有一个底部导航栏这使您可以在它们之间导航。我已经尝试使用 Navigator() 但它迫使我在主页上放置另一个按钮。不知道我说清楚没有,希望大家帮帮我。

谢谢!

更新 : 我已经使用了 getX 的包。

如果设置页面不包含底部应用栏,那么您可以使用 Navigator.of(context).pop() 或者您可以使用顶部应用栏并设置 automaticallyImplyLeading = true 以显示也会弹出的后退按钮.

这是我的底部应用栏之一的示例,它允许跨多个页面进行流畅的导航:

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, 34, 78, 1),
          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,
                        color: Colors.grey[600],
                      ),
                title: Container(
                  height: 0,
                )),
            BottomNavigationBarItem(
                icon: _currentIndex == 2
                    ? Icon(Icons.dashboard, color: Colors.white)
                    : Icon(Icons.dashboard, color: Colors.grey[600]),
                title: Container(
                  height: 0,
                )),
            BottomNavigationBarItem(
                icon: _currentIndex == 3
                    ? Icon(
                        Icons.person,
                        color: Colors.white,
                      )
                    : Icon(Icons.person, color: Colors.grey[600]),
                title: Container(
                  height: 0,
                )),
            BottomNavigationBarItem(
                icon: _currentIndex == 4
                    ? Icon(
                        Icons.people_alt,
                        color: Colors.white,
                      )
                    : Icon(Icons.people_alt, color: Colors.grey[600]),
                title: Container(
                  height: 0,
                )),
          ],
        ),
      ),
    );
  }

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}

我的应用程序(登录后)导航到这里,所有导航都在这里控制,除了我使用后退按钮和 pop() 的扩展屏幕。