How to Disable Swipe to Navigate Back In iOS Flutter?
AppBar Widget or top App Bars is a collection of widgets located at the top of the app, for wrapping our app’s title, icon, and action link. So in this article How to Disable Swipe to Navigate Back In iOS Flutter.
How to Disable Swipe to Navigate Back In iOS Flutter?
When we needed the user to be able to go back by pressing the “native” back button on the AppBar Widget and I found this niche little flag: userGestureInProgress on the Navigator object.
onWillPop: () async { if (Navigator.of(context).userGestureInProgress) return false; else return true; },
WillPopScope is the correct way to do this.
It is not complicated. It’s a one-liner :
WillPopScope( onWillPop: () async => false, child: <children here> )
So 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.
Open your project in Xcode, find AppDelegate.swift, and add the following:
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController; controller.navigationController? .interactivePopGestureRecognizer?.isEnabled = false;
MaterialPageRoute has a parameter called fullscreenDialog which is set to false by default. When true your page animates a bit differently and swipe to go back on iOS will be disabled.
So here’s an example usage:
Navigator.of(context).push( MaterialPageRoute(builder: (_) => HomePage(), fullscreenDialog: true));
Conclusion:
Thanks for Reading !!! Keep Learning!!! Keep Fluttering!!!
So in this article, we have been through how to disable swipe to navigate back in iOS flutter.
Let us know in the comments, how much did you learn from the article 🙂
Do let us know if you need any assistance with flutter development. We would love to assist you.
FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.