Reputation: 6680
I have an App that login to a specific page and execute some commands via Javascript. But when I start the App again it should open the login form. But, instead, it stays logged and goes to the user's screen.
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,
),
I tried to clean the cache, but perhaps it is not enough.
I/zygote64( 5259): Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
I/flutter ( 5259): cleaning the cache
Upvotes: 14
Views: 12591
Reputation: 31
You should clear cookies to start a new session, to clear cookies you can do the following `
late final WebViewCookieManager cookieManager = WebViewCookieManager();
void clearCookies() async {
await cookieManager.clearCookies();
}
and call the function in
init`
Upvotes: 3
Reputation: 1436
I think the problem is that you're not clearing the cookies. I was having the same issue with logging in to a page, and it staying logged in, which I fixed by clearing the cookies in the onWebViewCreated
callback:
onWebViewCreated: (webViewController) {
_controller.complete(webViewController);
webViewController.clearCache();
final cookieManager = CookieManager();
cookieManager.clearCookies();
},
Upvotes: 20