Flutter web local storage

浪子不回头ぞ 提交于 2021-01-28 19:11:57

问题


I am using localstorage to store some basic data in my flutter web app. Everything works fine but my problem is that the data is not available when I restart the browser.

// setting the data
html.window.localStorage["user-key"] = "Hello There";


//Reading it
String val = html.window.localStorage["user-key"];

I want to know if this is the intended behavior or intended behavior for testing in flutter web or an error on my side.


回答1:


According to the documentation it is supposed to stay across different sessions including closing and re-opening the browser. Check here.

I suspect you might be overwriting the key. So the idea would be check if the storage already has the key and then populate it as suggested in the documentation.

Also in flutter web debug mode you are opening a new profile of chrome instance if I am right, which doesn't have access to other instance storage. Correct me if I am wrong.

You can test this by accessing the URL in your usual browser instance instead of the one opened by flutter and closing it and reopening it again.

There are several other posts in SO which talk about this behavior of local storage and possible causes.



来源:https://stackoverflow.com/questions/60848470/flutter-web-local-storage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!