1

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

Rithin
  • 21
  • 1
  • 8

1 Answers1

0

WillPopScope will cause this. See more detail in https://github.com/flutter/flutter/issues/14203

mickey
  • 77
  • 9
  • 1
    Please elaborate and add your answer verbosely instead of posting a link-only answer as some links might become inaccessible in the future. – Wim Ombelets Apr 29 '21 at 10:22