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小郭11 小时前
Flutter A2UI 1.0 ,原来的 genui 也正式换成了这一套 SDK 了
android·前端·flutter
LinXunFeng12 小时前
A2UI 1.0 详解:让 AI 生成 Flutter 界面,还不怕它乱写
前端·flutter·agent
好的佩奇1 天前
Dart 之元数据与注解
android·flutter·dart
恋猫de小郭3 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
好的佩奇4 天前
蓝牙之设备角色与连接
android·flutter·蓝牙
SoaringHeart5 天前
Flutter最佳实践:用 flutter_html 渲染富文本
前端·flutter
恋猫de小郭5 天前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
程序员老刘6 天前
跨平台开发地图 | 2026年11月
flutter·ai编程·客户端
传奇开心果编程6 天前
【Flutter踩坑排雷】第30课:异常未捕获坑|未捕获异常直接闪退,全局兜底故障处理
android·flutter·ios·移动开发·dart·ui框架·声明式ui
恋猫de小郭6 天前
Flutter Native Interop 稳定了,Platform Channel 要退场了
android·前端·flutter