Back to results for “SQLite & Local Databases (sqflite)”
Flutter › SQLite & Local Databases (sqflite)

What is sqflite, and how does it let you actually use a genuinely full relational SQLite database directly within a Flutter app?

Beginner

Answer

sqflite is a genuinely popular Flutter plugin providing direct access to SQLite, a lightweight, fully embedded relational database engine, letting you properly create tables, run genuine SQL queries, and manage relational data directly on a user's own device, and it is genuinely well suited for an app needing to store a fairly large amount of genuinely structured, deeply relational data, such as an inventory system with several separate related tables, considerably better suited than a considerably simpler key value store like SharedPreferences or Hive.
final db = await openDatabase('my_database.db', version: 1, onCreate: (db, version) {
  db.execute('CREATE TABLE orders(id INTEGER PRIMARY KEY, total REAL)');
});
Real-world example An inventory management app uses sqflite to properly store several genuinely related tables including products, warehouses, and detailed transaction history, taking genuine advantage of SQL's own considerably more powerful relational query capabilities compared to a considerably simpler NoSQL alternative.

Common follow-ups: What is the specific practical difference between sqflite and Hive in terms of exactly what kind of data each one is genuinely best suited for?;How do you actually properly and correctly close a sqflite database connection once it is genuinely no longer actually needed?