Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support LocalStorage #51

Merged

Conversation

jparound30
Copy link
Contributor

related #48

best regards.

Copy link
Collaborator

@lejard-h lejard-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks :)

@lejard-h lejard-h merged commit 6502546 into fluttercommunity:master Mar 25, 2018
@ryo204
Copy link

ryo204 commented Jun 22, 2018

@jparound30
Thanks for adding local storage feature. It is great and is exactly what I need.

I tried to use it in my project but I don't know how to. Could you please spare some minutes to give me a code example on how to use your feature to set local storage for webview?

I posted [my question] (https://stackoverflow.com/questions/50960945/flutter-webivew-how-to-set-local-storage) but unfortunately no one was able to help me.

I would really appreciate it if you could show me how in the code.

Many thanks

@jparound30
Copy link
Contributor Author

@ryo204

Unfortunately, I was not considering operating LocalStorage from outside WebView.

Although I tried a little investigation,
there seems to be a case in which execution of evalJavascript or access to LocalStorage can not be performed normally due to the timing of WebView startup, the timing of page loading, and so on.

You may be able to avoid it by waiting until the first page loading is completed and then accessing LocalStorage with evalJavascript.

like this.

// On urlChanged stream
StreamSubscription<WebViewStateChanged> _onStateChanged;
_onStateChanged = flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged state) {
  if (mounted) {
    if (state.type == WebViewState.finishLoad) {
      flutterWebviewPlugin.evalJavascript(
          "window.localStorage.setItem('LOCAL_STORAGE','SOMETOKEN');" +
              "document.getElementById('showLocalStorageBtn').click();"
      );
    }
  }
});

i hope you will find it helpful.

thanks.

@ryo204
Copy link

ryo204 commented Jun 25, 2018

@jparound30

Thank you for your help!
I was able to produce the desired behavior thanks to your guidance.

@crnaosa
Copy link

crnaosa commented Jun 26, 2018

@jparound30

Thanks for the plugin, it seems to be exactly what I'm looking for, but I'm not sure if I'm using it correctly. I use the flutter webview plugin to play video from firebase storage, and expected that after the playing the video once, it would play it next time from local storage. Did I misunderstood the use? Actually, I wasn't able to find some instructions...

I would really appreciate some instructions of how to use the plugin. I've tried to use it like this:

child: WebviewScaffold( withLocalStorage: true, url: url, ),

@jparound30
Copy link
Contributor Author

@crnaosa
I think you misunderstood.

LocalStorage is a feature of Web Browser for key/value store.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

There is no functional relationship with firebase storage.

@crnaosa
Copy link

crnaosa commented Jun 26, 2018

Understood, thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants