Flutter: Disable Swipe to Navigate Back in iOS

后端 未结 7 1075
一向
一向 2020-12-16 15:25

I\'m new to flutter development, and find it a bit frustrating in iOS when you have a navigation drawer and when you swipe to open it, it\'ll perform a Navigation.of(c

相关标签:
7条回答
  • 2020-12-16 16:06

    I am not quite sure what you want to achieve, but most of the time when people want to get rid of the back functionality, because they don't wanna enable the user to control the auth mechanism. For example after the users log in, you don't want them to navigate to the Login page by just press on the back button(or swipe back in iOS). A potential solution is, using pushNamedAndRemoveUntil.

    Future<T> pushNamedAndRemoveUntil<T extends Object>(BuildContext context, String newRouteName, RoutePredicate predicate)

    Push the route with the given name onto the navigator that most tightly encloses the given context, and then remove all the previous routes until the predicate returns true.

    Example code: pushNamedAndRemoveUntil(context, '/home', ModalRoute.withName('/home'));

    Note: use this method to some certain extent, because you might mess up your navigation history.

    0 讨论(0)
提交回复
热议问题