I am building a Flutter App right now, that has a login, which routes to a new screen, which contains a scaffold, which holds a webView as a body. For the navigation I use
Navigator.pushNamed(
context,
webshopRoute,
arguments: WebshopArguments(initialUrl: shopUrl),
);
When I browse in the webView I want to go back - within the webView - with a swipe gesture from right to left(for phones that don't have a back button like my Pixel 4). But what the swipe does right now is that it jumps back to the Login Screen.
The only posts I found here where how to disable it, which I don't want.
Thank you very much!
Ok so the trick was to wrap the scaffold with WillPopScope and call goBack() on the controller inside onWillPop.
late WebViewController _webViewController;
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
_webViewController.goBack();
return false;
},
child: Scaffold(
body: SafeArea(
child: WebView(javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_webViewController = webViewController;
},
.....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.