How to use local Sqlite database efficiency in Dart/Flutter

2.2k Views Asked by At

I'm a newbie in flutter and android application. I have developed a quiz app. It loading a Json data from Firebase and i want to save it to Sqlite(for query fast purpose). My problem is Json data quite complicated, it have multi data array nested(refer Json data as bellow)

Since Sqlite doesn't allow nesting tables within tables, I not sure how to organize or convert the data to Sqlite most reasonable. I am thinking of saving all my Json as a String, but I know it not a good idea. Any have a better idea, very appreciate it

{
    "title": "TEST title",
    "des": null,
    "ver": 0,
    "partOne": [
        {
            "number": 1,
            "correctAns": 3,
            "question": "question 1 here?",
            "ansA": "answer A here",
            "ansB": "answer B here",
            "ansC": "answer C here",
            "ansD": "answer D here"
        },
        // about 100 question
        ...
    // about 100 part
    ...
    ]
}
2

There are 2 best solutions below

1
On BEST ANSWER

you can try Hive or Objectbox. Both of them are local DB that easy to use and also faster than SQFLite.

If you want to learn more about Hives, you can learn here

If you want to learn more about Objectbox, you can learn here

this is the database performance benchmark between Hive, Objectbox, and SQFLite (image source: link) image

I have try both hive and objectbox. Its recommended for you if you have a complex data and want to solve the storing problem.

Goodluck, hope it helps!

1
On

Its better if you use Hive, its a local DB that will let you solve your complex data problem. Super easy and works much faster than SQflite

Things you need:

And of course some tutorial as well. So,

Cheers and good luck!