How to save to web local storage in flutter web

后端 未结 6 2004
渐次进展
渐次进展 2020-12-30 01:02

I have a web site built with flutter for web and currently, am trying to save to web local storage or cookie but can\'t seem to find any plugin or way to ar

6条回答
  •  佛祖请我去吃肉
    2020-12-30 01:34

    I ran into a similar issue where my preferences weren't being persisted across runs. I thought window.localStorage was broken. I discovered that Flutter was simply launching with a new port number every time by default, so window.localStorage was getting wiped out.

    This ticket talks about setting an explicit port. This fixed my issue, and now window.localStorage persists across runs:

    https://github.com/Dart-Code/Dart-Code/issues/1769

    In VS Code, you can set the port number in your launch.json file:

    {
        "name": "Flutter",
        "request": "launch",
        "type": "dart",
        "args": ["--web-port", "8686"]
    },
    

提交回复
热议问题