【问题标题】:BackButton and BottomNavigationBarBackButton 和 BottomNavigationBar
【发布时间】:2020-10-18 15:54:13
【问题描述】:

我想在我的页面之间导航,当我在设置页面上时,我想要一个返回按钮,可以将我带到主页,收藏夹也是如此,从我的页面还有一个底部导航栏,允许您可以在它们之间导航。我已经尝试过使用 Navigator() 但它迫使我在主页上放置另一个按钮。我不知道我是否说清楚了,但我希望你能帮助我。

谢谢!

更新:我使用了 getX 的包。

【问题讨论】:

    标签: flutter dart navigation back


    【解决方案1】:

    如果设置页面不包含底部应用栏,那么您可以使用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() 的扩展屏幕。

    【讨论】:

    • 我已经有一个BottomNavigationBar。我想在我的收藏夹和设置屏幕的 AppBar 中创建一个后退按钮,而不是在我的主屏幕的 Appbar 中。 BackButtons 转到 HommePage。
    猜你喜欢
    • 2021-09-12
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2019-07-14
    相关资源
    最近更新 更多