Unable to pass Local Storage in Flutter Webview

576 views
Skip to first unread message

Hyder Hussain

unread,
Apr 22, 2021, 12:12:20 PM4/22/21
to Flutter Development (flutter-dev)
Hey.
Can anyone tell me how to pass local storage to webview in Flutter? I have searched online and couldn’t find much. Following is the error I get when trying to pass local storage. I am not sure if this is the right way to do so?

```
body: WebView(
initialUrl: _url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) async { await cookieManager.setCookies([
Cookie(cookieName, cookieValue)
..domain = domain
..expires = DateTime.now().add(Duration(days: 10))
..httpOnly = false,
Cookie(cookieName2, cookieValue2)
..domain = domain
..expires = DateTime.now().add(Duration(days: 10))
..httpOnly = false,
Cookie(cookieName3, cookieValue3)
..domain = domain
..expires = DateTime.now().add(Duration(days: 10))
..httpOnly = false
]);
await controller.evaluate javascript(
'localStorage["tenant_auth_setting"] = $localStorageCookie2');

```



A screenshot of the error is attached:


Screenshot 2021-04-22 at 9.41.35 PM.png
Reply all
Reply to author
Forward
0 new messages