Webview 不断刷新——Flutter InAppWebView

问题描述

所以我试图在 Webview 中设置一个 cookie(设置用户令牌),但我遇到了页面不断刷新的问题。这是代码:

InAppWebViewController _webViewController;
  final expiresDate = DateTime.now().add(Duration(days: 3)).millisecondsSinceEpoch;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: DashboardPageTitlesAtom(
        title: widget.title,leading: IconButton(
          icon: Icon(Icons.arrow_back),onPressed: () {
            Navigator.pop(context);
          },),trailing: IconButton(
          icon: Icon(CupertinoIcons.refresh),onPressed: _webViewController == null ? null : () => _webViewController.reload(),body: Column(
        children: [
          Divider(
            thickness: 1,height: 1,Expanded(
            child: InAppWebView(
                initialOptions: InAppWebViewGroupOptions(
                  crossPlatform: InAppWebViewOptions(
                    javaScriptEnabled: true,clearCache: false,onWebViewCreated: (InAppWebViewController controller) async {
                  _webViewController = controller;
                },onLoadStop: (InAppWebViewController controller,url) async {
                  try {
                    final token = await getToken();
                    await _webViewController.evaluateJavascript(
                      source:
                          'document.cookie = "accessToken=${token}"; secure=true; httpOnly=false; sameSite=None',);
                    await _webViewController.loadUrl(url: widget.url);
                  } catch (e) {
                    print(e.toString());
                  }
                }),],);
  }

问题是设置cookie的唯一方法是在评估javascript后刷新页面并且页面刷新不会停止。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)