我有一个应用程序可以登录到特定页面并通过 Javascript 执行一些命令。但是当我再次启动应用程序时,它应该打开登录表单。但是,相反,它保持登录状态并转到用户屏幕。
child: WebView(
initialUrl:
'https://thepage.com/m/customer/account/login/',
onWebViewCreated: (c) {
_webviewController = c;
print("cleaning the cache");
_webviewController.clearCache();
},
onPageFinished: (String page) async {
setState(() {
_isPageLoaded = true;
});
},
javascriptMode: JavascriptMode.unrestricted,
),
Run Code Online (Sandbox Code Playgroud)
我试图清理缓存,但也许这还不够。
I/zygote64( 5259): Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
I/flutter ( 5259): cleaning the cache
Run Code Online (Sandbox Code Playgroud)
我认为问题在于您没有清除 cookie。我在登录页面时遇到了同样的问题,并且它保持登录状态,我通过清除onWebViewCreated
回调中的 cookie 解决了这个问题:
onWebViewCreated: (webViewController) {
_controller.complete(webViewController);
webViewController.clearCache();
final cookieManager = CookieManager();
cookieManager.clearCookies();
},
Run Code Online (Sandbox Code Playgroud)