Tried flutter webview. Implemented WillPopScope
to control the back press referring this example. In android swipe to go back gestures works, but in ios it doesn't work. This does not detect the gesture. How to solve this?
Code:
WebViewController controllerGlobal;
Future<bool> _exitApp(BuildContext context) async {
print('back press');
if (await controllerGlobal.canGoBack()) {
print("onwill goback");
controllerGlobal.goBack();
} else {
Scaffold.of(context).showSnackBar(
const SnackBar(content: Text("No back history item")),
);
return Future.value(false);
}
}
class _MyAppState extends State<MyApp> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _exitApp(context),
child: Scaffold(
body: SafeArea(
child: Builder(
builder: (BuildContext context) {
return WebView(
initialUrl: 'https://flutter.dev',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
);
},
),
),
),
);
}
}
Note: Tested in ios simulator only