I am using the flutter_custom_tabs package to open a URL in my Flutter app. I need to clear the cookies stored in the browser when the custom tabs browser is closed.
I used a native method (Kotlin for Android, swift for iOS) to clear cookies, but it didn’t work as expected. Although the native scripts executed correctly when called from Flutter, the cookies in the custom tabs browser remained uncleared.
Below is the native code I used:
Android:
privatefun clearBrowserCache() {
WebView(this).clearCache(true)
CookieManager.getInstance().removeAllCookies(null)
WebStorage.getInstance().deleteAllData()
}
iOS:
privatefuncclearBrowserCache() {
let dataStore =WKWebsiteDataStore.default()
let dataTypes =WKWebsiteDataStore.allWebsiteDataTypes()
let dateFrom =Date(timeIntervalSince1970: 0)
dataStore.removeData(ofTypes: dataTypes, modifiedSince: dateFrom, completionHandler: {})
}
Is there a way to clear the cookies of the browser opened with flutter_custom_tabs? Or is there any workaround or alternative solution to achieve this functionality?
Top comments (0)