Session not saving in ios flutter webview app
Asked Answered
M

1

7

I have some issue with storing session details in my ios app. I created a webview app. Whenever i close the app after logging in, it logs me out and asks for credentials everytime. This is working fine for my android app. Any fix for this.

Morbihan answered 14/12, 2022 at 5:6 Comment(0)
C
1

You can store the session by calling below code:-

 onLoadStop: (controller, url) async {
        if (url == null) {
          return;
        }
        final cookieManager = CookieManager.instance();
        final expiresDate = DateTime.now()
            .add(const Duration(hours: 24))
            .millisecondsSinceEpoch;

        List<Cookie> cookieList = await cookieManager.getCookies(url: url);
        cookieList.where((cookie) => cookie.expiresDate == null).forEach(
              (cookie) => cookieManager.setCookie(
                url: url,
                name: cookie.name,
                value: cookie.value,
                path: cookie.path ?? '/',
                domain: cookie.domain,
                expiresDate: expiresDate,
                isSecure: cookie.isSecure,
                isHttpOnly: cookie.isHttpOnly,
                sameSite: cookie.sameSite,
              ),
            );
      }

You have to store session or cookies for web view using CookieManager and you can call this code when your url is loading is completed.

Clausewitz answered 25/9, 2023 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.