Search code examples
flutterdartlocal-storagesharedpreferencesandroid-room

Flutter local database storage


Currently I'm creating a user registration criteria and it have three registration pages. For each completion of user registration page I want to store it in local storage. If the user closes the app before the 3 level of registration, I want to show the entered details of completed pages without api calling.

So which is the best way of storing data locally in flutter like room database, shared preferences etc...


Solution

  • It depends on the data you want to store. There are several options from relation databases (sqlite) to key-value stores.

    The easiest and best performing stores are

    If you have complex Data to store and want the advantages of relational storage your primary options are

    • Sqflite (a sqlite plugin for Flutter with raw SQL)
    • Drift (previously Moor, is a full-fledged ORM with code/table generation on top of sqlite)

    I think that in your case, Hive or ObjectBox would be best, as the data you are storing is quite simple and does not have many relationships. If you want to store relational data, I personally prefer Drift to Sqflite, as Drift has improved a lot recently.

    Of course, there are the secure storage and shared preferences, which should only contain very loose and simple data.