Issue
I need help to set multiple items in session storage of the flutter webview.
I am using this package - webview_flutter: ^3.0.1
=> here
I want to open a URL that will enable users to take further action in a functionality that is already present on a website. The website's code is written in a way that it accesses data from the session storage -> like auth token and user id and so on. If I am unable to provide this data in session storage then website will redirect to login.
I have tried doing this ->
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
webViewController.runJavascript(
'sessionStorage.setItem("userCode", "000"); sessionStorage.setItem("role", "40");');
},
Solution
I figured out a way but it does not use the official flutter webview plugin.
I used this plugin - flutter_inappwebview
I was able to set local storage and session storage both ->
onLoadStart:
(InAppWebViewController controller, Uri? url) async {
await controller.evaluateJavascript(source: """
window.localStorage.setItem("userCode", "${userDetails.userId}");
""");
await controller.evaluateJavascript(source: """
sessionStorage.setItem("userCode", "${userDetails.userId}");
sessionStorage.setItem("Role", "${userDetails.role}");
""");
},
Answered By - Rahul Mishra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.