Flutter · One codebase, native feel

How do you choose local storage in Flutter?

Easystorageshared preferencessqlitesecurityUpdated Oct 2026
Quiz this track

Short answer

Use shared_preferences for small key-value settings, SQLite or Drift for structured relational data, and secure storage for tokens. Choose based on query needs, size, encryption and migration requirements.

Local persistence is not one problem. Preferences are small key-value pairs. Structured records need queries and migrations. Secrets need platform-backed encryption. Large binary data belongs in files or a database, not in preferences. Picking one tool for all four creates either insecure secrets or unmaintainable queries.

dart
Future<void> saveThemeMode(String mode) async {
  final prefs = await SharedPreferences.getInstance();
  await prefs.setString('theme_mode', mode);
}

Future<String?> readThemeMode() async {
  final prefs = await SharedPreferences.getInstance();
  return prefs.getString('theme_mode');
}
  • shared_preferences is for simple flags and settings, not for lists of records
  • sqflite or Drift suits relational data, joins and migrations
  • Hive or Isar can be fast for object stores, but evaluate maintenance and query needs
  • flutter_secure_storage uses Keychain on iOS and Keystore-backed storage on Android
  • path_provider gives a correct application documents or cache directory

Migration and consistency

Any schema will change. Version the database and write explicit migrations that run once, with tests from old fixtures. Decide what happens when a migration fails: preserve the old data, surface an error, or reset only cached non-critical data. Never silently delete user data.

Preferences are not encrypted. Storing an auth token there is a security bug on shared or compromised devices. Use secure storage and keep only non-sensitive metadata in preferences.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1When would you choose SQLite over shared_preferences?
  2. 2Where should an access token be stored?
  3. 3How do you handle a schema migration failure?
  4. 4What belongs in the cache directory rather than documents?

Say it in the interview

I match the storage to the data. Small settings go in shared_preferences, structured records go in SQLite or Drift with versioned migrations, and tokens go in secure storage backed by Keychain or Keystore. Files use path_provider directories. I plan migrations and failure handling up front because deleting user data to fix a schema problem is not acceptable.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Flutter mock interview and get scored feedback on depth, clarity and confidence.