Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter's Webview - How to clear session status?

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
like image 862
alexpfx Avatar asked Jul 13 '19 17:07

alexpfx


1 Answers

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();
},
like image 109
Alfred Jingle Avatar answered Nov 11 '22 13:11

Alfred Jingle