In order to avoid frustrating users, your app needs to save data that survives an app restart. Saving app data to some type of storage that survives app restarts is called data persistence.
We can use 3 approaches to persist data in flutter
1. Persist data with SQLite
2. Read and write files
3. Store key-value data on disk
If you are writing an app that needs to persist and query large amounts of data on the local device, consider using a database instead of a local file or key-value store. In general, databases provide faster inserts, updates, and queries compared to other local persistence solutions.
Flutter apps can make use of the SQLite databases via the sqflite plugin available on pub.dev. This recipe demonstrates the basics of using sqflite to insert, read, update, and remove data about various Dogs.
If you are new to SQLite and SQL statements, review the SQLite Tutorial to learn the basics before completing this recipe.
This recipe uses the following steps:
Add the dependencies.
Define the Dog data model.
Open the database.
Create the dogs table.
Insert a Dog into the database.
Retrieve the list of dogs.
Update a Dog in the database.
Delete a Dog from the database.