Session 10
Session 10
SQLite in Flutter
o Data persistence allows your app to store information even after the app is closed.
o Flutter offers several methods for local storage, including SharedPreferences (for
small key-value pairs) and SQLite (for more structured, relational data).
2. SharedPreferences in Flutter
What is SharedPreferences?
• SharedPreferences is used to store small amounts of simple data (key-value pairs), such
as user settings, preferences, or state information.
• It is asynchronous and stores data in persistent storage that remains available even after
the app is closed and reopened.
Key Concepts:
• Data types that can be stored include int, double, String, bool, and List<String>.
• It’s commonly used for saving settings like user preferences (e.g., theme, language, etc.).
3. sqflite in Flutter
What is SQLite?
• SQLite is a relational database management system used to store large and structured
data.
• It supports SQL queries and can store complex data types (multiple tables, foreign key
relationships, etc.).
Why sqflite?
• sqflite is a Flutter plugin that allows us to use SQLite databases for local storage in Flutter
applications.
• It is suitable for apps that need to manage larger and more complex data, such as to-do
lists, product catalogs, etc.
Key Concepts:
• SQLite is more structured than SharedPreferences, supporting tables, columns, rows, and
foreign key relationships.
• CRUD operations: Create, Read, Update, Delete are performed using SQL queries.
Example of Using sqflite
5. Practical Exercise
• SharedPreferences Exercise:
o Create a simple app that allows the user to toggle between light and dark themes.
Save the theme preference using SharedPreferences.
• sqflite Exercise:
o Create a simple to-do list app where users can add, edit, and delete tasks. Use
SQLite to store tasks persistently.