简体   繁体   English

在 flutter webview 中滑动到 go 后不起作用

[英]Swipe to go back not working in flutter webview in ios

Tried flutter webview.试过 flutter webview。 Implemented WillPopScope to control the back press referring this example.实施WillPopScope以控制参考示例的后压。 In android swipe to go back gestures works, but in ios it doesn't work.在 android 滑动到 go 后退手势有效,但在 ios 它不起作用。 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注意:仅在 ios 模拟器中测试

WillPopScope will cause this. WillPopScope 会导致这种情况。 See more detail in https://github.com/flutter/flutter/issues/14203https://github.com/flutter/flutter/issues/14203中查看更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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