Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Disable Swipe to Navigate Back in iOS and Android

Tags:

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(context).pop(). I would like to disable this "swipe to pop" behavior in iOS. I have been perusing the documentation, but without much luck.

I do see something referred to as a WillPopScope which seems to do the trick (github issue for it here), but I'm not 100% sure if this is the "correct" way to do it (it seems too complicated... it should be easier... like a setting on the root app).

like image 223
James Gilchrist Avatar asked Mar 07 '18 21:03

James Gilchrist


People also ask

How do you stop swipe in flutter?

To disable Swipe TabBar user can by changing how the page view should respond to user input using the physics property. and we have a NeverScrollableScrollPhysics for that purpose so just change physics to that like this : You can disable swiping from TabBarView()


1 Answers

WillPopScope is the correct way to do this.

(it seems too complicated... it should be easier... like a setting on the root app).

It is not complicated. It's a one liner :

WillPopScope(   onWillPop: () async => false,   child: <children here> ) 

A configuration file would make things more complicated as it's harder to read and maintain.

And remember that in flutter everything is a widget not just half of them. Authentification, configurations, everything.

like image 138
Rémi Rousselet Avatar answered Sep 16 '22 14:09

Rémi Rousselet