Doubletab cupertinobottomnavigationbar到达家庭页面

发布于 2025-02-02 02:52:16 字数 1112 浏览 4 评论 0原文

我在应用程序中使用Cupertinobottomnavigationbar。一切正常,但是我想实现一个功能。以Spotify为例,您可以在底部navbar的项目中推入新屏幕,并始终通过双击底部努力键返回开始页面。 有没有办法在扑朔迷离中实现这一目标?

class CupterinoBottomNav extends StatelessWidget {
  const CupterinoBottomNav({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        backgroundColor: Colors.grey,
        items: const [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.home_filled,
                size: 28,
              ),
              label: 'Home'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.text_fields_sharp,
                size: 28,
              ),
              label: 'Test'),
        ],
      ),
      tabBuilder: (context, index) {
        switch (index) {
          case 0:
            return CupertinoTabView(builder: (context) => const Homepage());
          case 1:
          default:
            return CupertinoTabView(builder: (context) => const Test());
        }
      },
    );
  }
}

I am using the CupertinoBottomNavigationBar in my app. Everything works well, however there is one feature I would like to implement. Taking Spotify as an example, you can push to new screens within an item of the BottomNavBar and always return to the starting page by double tapping the BottomNavigationBar.
Is there a way to implement this in flutter?

class CupterinoBottomNav extends StatelessWidget {
  const CupterinoBottomNav({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        backgroundColor: Colors.grey,
        items: const [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.home_filled,
                size: 28,
              ),
              label: 'Home'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.text_fields_sharp,
                size: 28,
              ),
              label: 'Test'),
        ],
      ),
      tabBuilder: (context, index) {
        switch (index) {
          case 0:
            return CupertinoTabView(builder: (context) => const Homepage());
          case 1:
          default:
            return CupertinoTabView(builder: (context) => const Test());
        }
      },
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妖妓 2025-02-09 02:52:16

您可以使用Inkwell小部件来收听双水龙头,然后有几种方法可以导航到主页。一种方法是使用 name路由然后使用以下方式导航回家:

Navigator.popUntil(context, ModalRoute.withName('/home'));

You can use the InkWell widget to listen for the double tap and then there are a couple of ways to navigate home to your home page. One way would be to use name routes and then navigate home using:

Navigator.popUntil(context, ModalRoute.withName('/home'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文