flutter开发实战 - inappwebview设置cookie

flutter开发实战-inappwebview设置cookie

在使用inappwebview时候,需要设置cookie,这里记录一下

一、在initialUserScripts中设置cookie

在inappwebview中有一个initialUserScripts,可以初始化设置cookie等,我们可以通过该属性来设置cookie。

复制代码
initialUserScripts: UnmodifiableListView<UserScript>([
              UserScript(
                  source:
                      "document.cookie='token=${TokenAuth.getToken()};domain='.inice.cn';path=/'",
                  injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START),
            ]),

二、在onWebViewCreated回调设置cookie

在inappWebview设置cookie,可以使用到CookieManager,设置cookie

复制代码
CookieManager.instance().setCookie(
          url: Uri.parse(url),
          name: "token",
          value: TokenAuth.getToken(),
          domain: ".inice.cn",
          isHttpOnly: false,
        );

在onWebViewCreated方法中调用上面的代码

复制代码
onWebViewCreated: (controller) {
    webViewController = controller;
	
	CookieManager.instance().setCookie(
          url: Uri.parse(url),
          name: "token",
          value: TokenAuth.getToken(),
          domain: ".inice.cn",
          isHttpOnly: false,
        );
},

三、小结

flutter开发实战-inappwebview设置cookie。描述可能不是特别准确,请见谅。

学习记录,每天不停进步。

相关推荐
恋猫de小郭7 小时前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
好的佩奇19 小时前
蓝牙之设备角色与连接
android·flutter·蓝牙
SoaringHeart2 天前
Flutter最佳实践:用 flutter_html 渲染富文本
前端·flutter
恋猫de小郭2 天前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
程序员老刘3 天前
跨平台开发地图 | 2026年11月
flutter·ai编程·客户端
传奇开心果编程3 天前
【Flutter踩坑排雷】第30课:异常未捕获坑|未捕获异常直接闪退,全局兜底故障处理
android·flutter·ios·移动开发·dart·ui框架·声明式ui
恋猫de小郭3 天前
Flutter Native Interop 稳定了,Platform Channel 要退场了
android·前端·flutter
好的佩奇4 天前
Dart 之可迭代对象与生成器
android·flutter·dart
恋猫de小郭4 天前
Flutter Analyzer 系列坑推进,必看,AI 时代这玩意最吃你内存
android·前端·flutter
LinXunFeng5 天前
拿竞品 App 一扫,技术栈全暴露了
android·flutter·开源