My Flutter application flow works like this:
- User logins
- If login successfully, server returns a token
- Set token to local storage in webview
- Open
Webview
fullscreen to a specific URL
I am using this Webview plugin. The sample code shows that it supports local storage (it has a withLocalStorage
option) but does not show how to use it.
I tried:
- Create new
FlutterWebviewPlugin
instance
- Set local storage on the newly-created instance by calling method
evalJavascript
call launch
on the instance, set withJavascript
, withLocalStorage
to true
and launched it to a URL;
//1
final flutterWebviewPlugin = new FlutterWebviewPlugin();
//2
flutterWebviewPlugin.evalJavascript("window.localStorage.setItem('token','SOMETOKEN')");
//3
flutterWebviewPlugin.launch(
"https://SOMEURL",
withLocalStorage: true,
withJavascript: true);
If I correctly set the local storage, the Webview
would show account page; otherwise a login page (which was what happened)
I also note that the evalJavascript
invocation doesn't seem to work. Also, changing order of step 2 and step 3 doesn't change anything.
Note that I'm aware of this question. The answer provided doesn't show how to set the local storage either, and it doesn't show the Webview
fullscreen so it won't solve my problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…