Back to results for “Preferences”
Flutter › Local Data Storage with SharedPreferences

What is the shared_preferences package, and what kinds of genuinely simple data is it actually genuinely well suited for storing directly on a user's own device?

Beginner

Answer

The shared_preferences package provides a genuinely simple key value storage mechanism specifically for persisting small pieces of primitive data, such as strings, booleans, integers, and doubles, directly on a user's own device across separate individual app sessions, and it is genuinely best suited for storing simple app settings and preferences, such as a user's chosen theme, whether they have already seen a particular onboarding screen, or their preferred notification setting, rather than genuinely large amounts of structured data, which would generally be considerably better handled instead by a proper genuine database such as Hive or SQLite.
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('hasSeenOnboarding', true);
final hasSeenOnboarding = prefs.getBool('hasSeenOnboarding') ?? false;
Real-world example An app properly remembers whether a user has already genuinely seen its own initial onboarding screens using SharedPreferences, correctly avoiding showing that same onboarding flow again every single time that particular user actually reopens the app.

Common follow-ups: What genuinely happens to data stored using SharedPreferences if a user actually uninstalls the app?;What is the specific practical difference between SharedPreferences and Hive in terms of exactly what kind of data each one is genuinely best suited for?