Local Storage (shared_preferences & sqflite)

June 02, 2026 1 min read

Save data between app launches. Use shared_preferences for small key/value settings and sqflite (SQLite) for structured datasets.

shared_preferences

final prefs = await SharedPreferences.getInstance();
await prefs.setBool('darkMode', true);
final dark = prefs.getBool('darkMode') ?? false;

sqflite (SQLite)

final db = await openDatabase('app.db', version: 1,
  onCreate: (db, v) => db.execute(
    'CREATE TABLE notes(id INTEGER PRIMARY KEY, title TEXT)'));
await db.insert('notes', {'title': 'Hello'});
final rows = await db.query('notes');
Tip: For a simpler local database, Hive is a fast, pure-Dart key/value store worth exploring.

Summary

Use shared_preferences for small settings and sqflite/Hive for structured local data.