Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe back gesture on iOS is overwritten by WillPopScope

If I am using WillPopScope to overwrite the BackButton behavior with a new route, it works fine. But on iOS, the automatic 'SwipeBack' gesture is not working any more. How can I set the SwipeBack gesture on iOS to push the current screen to the page with the class 'StartScreen'?

WillPopScope(onWillPop: (){
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => StartScreen(),
        ),
      );
    }
like image 547
user3532201 Avatar asked Feb 23 '19 13:02

user3532201


People also ask

How do I turn off swipe gestures in iOS?

Answer: A: As stated in this article, Switch between apps on iPad - Apple Support. To turn off the multifinger swipe gesture, go to Settings > Home Screen & Dock > Multitasking.


2 Answers

This may be a very late answer, but at the moment there is no clear opportunity to listen to this gesture

You can achieve the call to onWillPop when you press the back button, and at the same time do not block the gesture if you make a descendant class of the ModalRoute class (or its descendants, such as MaterialPageRoute) and override the hasScopedWillPopCallback method (however, the gesture will not call onWillPop)

like image 65
Artem Krupp Avatar answered Sep 28 '22 06:09

Artem Krupp


WillPopScope is not meant to affect navigation (I.e.: push a route on the navigator). It is meant for vetoing (preventing) navigation away from the current route when you don't want the user to navigate away. (For example, when it might result in data loss.)

Try CupertinoWillPopScope, as it allows you to conditionally veto the back navigation. So you can only block it when there's an actual need.

like image 39
triple7 Avatar answered Sep 28 '22 05:09

triple7