Flutter Web本地存储 [英] Flutter web local storage

查看:107
本文介绍了Flutter Web本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用localstorage在Flutter Web应用程序中存储一些基本数据.一切正常,但我的问题是,当我重新启动浏览器时,数据不可用.

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.

推荐答案

根据文档,该文档应该保留在不同的会话中,包括关闭和重新打开浏览器.在此处.

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.

如果在正确的情况下,您还可以在Flutter Web调试模式下打开 chrome实例的新配置文件,该实例无权访问其他实例存储.如果我错了,请纠正我.

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.

您可以通过在通常的浏览器实例中访问该URL来进行测试,而不是通过抖动打开并关闭该URL,然后再次将其重新打开.

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.

SO中还有其他几篇文章,它们讨论了本地存储的这种行为以及可能的原因.

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

这篇关于Flutter Web本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆