首页 > 解决方案 > 如何启用 webview cookie?

问题描述

我的错误截图我正在尝试使用 webview 在我的颤振应用程序中实现名为“cow pay”的支付网关,但我总是收到此错误。这是我的代码:

          WebView(
             initialUrl:
                  "my url",
              javascriptMode: JavascriptMode.unrestricted,
              onWebViewCreated: (WebViewController webViewController) {
                _controller.complete(webViewController);
              },
              javascriptChannels: <JavascriptChannel>{
                _toasterJavascriptChannel(context),
              },
              onPageStarted: (String url) {
                print('Page started loading: $url');
              },
              onPageFinished: (String url) {
                print('Page finished loading: $url');

              },
              gestureNavigationEnabled: true,
            )

标签: flutter

解决方案


尝试删除initialUrl: "my url",

另外,使用webview_cookie_manager插件

WebView(
      javascriptMode: JavascriptMode.unrestricted,

      onWebViewCreated: (WebViewController webViewController) async{
        _controller = webViewController;
        await cookieManager.setCookies([
          Cookie(cookieName, cookieValue)
            ..domain = domain
            ..expires = DateTime.now().add(Duration(days: 1))
            ..httpOnly = false
        ]);
        _controller.loadUrl("your URL");

      },
      )

推荐阅读