简体   繁体   中英

Swipe to go back not working in flutter webview in ios

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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM