简体   繁体   English

在 Flutter 中使用 BottomNavBar 向后滑动手势

[英]Swipe back gesture with BottomNavBar in Flutter

I'm using bottom navigation bar, and I need to push a view with bottom nav bar to be persistent.我正在使用底部导航栏,我需要推送带有底部导航栏的视图才能持久。

And this is the main page:这是主页:

MaterialApp(
        theme: ThemeData(
            pageTransitionsTheme: PageTransitionsTheme(builders: {
          TargetPlatform.android: CupertinoPageTransitionsBuilder(),
          TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
        })),
        home: Scaffold(
            body: IndexedStack(
              index: _pageIndex,
              children: const <Widget>[
                HomeView(),
                VideosSectionsView(),
                FavoritesView()
              ],
            ),
            bottomNavigationBar: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                showBottomPlayer ? bottomPlayer(context) : Row(),
                const SizedBox(height: 0),
                bottomNavigationBar()
              ],
            )));

The problem is, when I push a view from HomeView to SecondView, and push again to ThirdView, the swipe back gesture from the ThirdView (in left edge of the screen) send me back to HomeView, but I want it to send me to SecondView (so popping only one view, not all the stack) do you know to achieve this?问题是,当我将一个视图从 HomeView 推送到 SecondView,然后再次推送到 ThirdView 时,ThirdView 的向后滑动手势(在屏幕的左边缘)将我送回 HomeView,但我希望它将我送回 SecondView (所以只弹出一个视图,而不是所有的堆栈)你知道实现这个吗?

For that I use CupertinoPageRoute:为此,我使用 CupertinoPageRoute:

Navigator.of(context, rootNavigator: false).push(
    CupertinoPageRoute<bool>(
       fullscreenDialog: false, 
       builder: (BuildContext context) => SecondView()
    )
);

This is weird because if I set " rootNavigator " to true, it's working and I can pop only the last view of the stack, but the bottom nav bar is not persisted anymore in navigation !这很奇怪,因为如果我将“ rootNavigator ”设置为 true,它可以正常工作,我只能弹出堆栈的最后一个视图,但底部导航栏不再保留在导航中!

So I have to chose between a good swipe back gesture or persisted nav bar...所以我必须在良好的向后滑动手势或持久的导航栏之间做出选择......

There's no problem with getting back programmatically:以编程方式返回没有问题:

Navigator.of(context).pop(true);

So I want the same thing with Swipe Gesture, thanks all所以我想用滑动手势做同样的事情,谢谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM