Home > Mobile >  Managing flutter app and flutter web data locally
Managing flutter app and flutter web data locally

Time:12-13

I was working on a project to create a flutter to-do app to store data locally on mobile devices but I am not sure how to save data on local storage or something similar on the web.

So, I want to save the data locally if it is a mobile device and save the data on local storage if it's accessed via the web.

I don't know where to start, please advise.

CodePudding user response:

Options

You can use shared_preferences as it uses shared_preferences_android, shared_preferences_ios and shared_preferences_web (using IndexedDB) for the different platforms, note that this is not relevant for you directly as shared_preferences switches accordingly to the required platform.

Alternatively you can also use hive, as it also supports the web (via IndexedDB) and of course all other Platforms similar to shared_preferences.

The last option that also supports web is isar, it is however the most advanced of the three and is not well suited for this simple application at all.

Docs

All links link to their respective pub pages with enough docs. The only problem now is when to use which of the package.

Which to use

The flutter community is pretty divided over this, but as you can see shared_preferences has more likes and is from the flutter team at google themselves. However shared_preferences is very basic and if you are considering to save your own class objects (which is probably of use in an todo app) hive has a steeper learning curve to do so, but imo its better than just serialising it with and from json.

Of course json is completely fine, more so as you are probably a beginner, but for more complex applications hive (and if it gets really complex isar) is much better imo.

  • Related