SharedPreferences is a simple key–value storage used to persist small amounts of data on the device. It is intended for storing application preferences, not business data or sensitive information.
Typical use cases include theme selection, language choice, onboarding flags, or feature toggles.
SharedPreferences solves a very common problem in mobile apps: remembering simple settings between launches.
It is lightweight, easy to configure, and works consistently across platforms, which makes it a common choice for entry-level persistence in Flutter projects.
It acts as a persistent in-memory cache backed by a physical file. On initialization, it reads the entire XML file (Android) or plist (iOS) from disk into RAM. All subsequent reads happen synchronously from memory (instant access), while writes are committed asynchronously to disk to prevent blocking the UI thread. This architecture means it is not a database query engine, but a state synchronization mechanism for flat files.
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('isDarkMode', true);
final isDarkMode = prefs.getBool('isDarkMode') ?? false;Writes are asynchronous.
Reads are synchronous after initialization.
flutter_secure_storage.SharedPreferences does not support custom types, so objects must be serialized (for example to JSON) and stored as strings.SharedPreferences is ideal for storing small, simple pieces of data that represent user or application preferences rather than core business information. This includes settings like theme mode (light/dark), onboarding completion flags, last visited screens, or user-selected language. Because SharedPreferences provides a key-value storage API, it is easy to read and write values using a simple, efficient API, which makes it convenient for persisting lightweight state across app launches.
It is particularly useful when persistence needs are minimal and do not justify introducing a full local database. For instance, saving a toggle state in settings or remembering whether a tutorial has been completed are perfect use cases. SharedPreferences is cross-platform and integrates seamlessly with Flutter, requiring minimal setup while offering reliable storage for small datasets.
SharedPreferences should not be used for complex, structured, or sensitive data. Large datasets, such as product catalogs, user-generated content, or transaction histories, can quickly become unmanageable and lead to performance issues. Similarly, storing sensitive information like passwords or authentication tokens directly in SharedPreferences is insecure—developers should instead use secure storage solutions that encrypt data at rest.
Additionally, SharedPreferences is unsuitable when relationships between data objects or querying capabilities are required. For example, if you need to filter, sort, or join collections of records, a proper local database such as Hive, Drift, or Isar is far more appropriate. Using SharedPreferences in these cases can lead to brittle, hard-to-maintain code and increased risk of data corruption.
10 min • Oct 27, 2025
In this article, we’re sharing LeanCode’s 12 practical Flutter and Dart patterns that help you write less boilerplate, make your code cleaner, and catch mistakes earlier. Apply these patterns and you'll find yourself coding faster, communicating more clearly with your teammates, and spending less time debugging issues that the compiler could have caught.
15 min • Jul 30, 2020
There is always exciting technology our team wants to try out. We challenged them and asked for proof on how Flutter can bring value to the client. We are sharing the insights after making the first 10 commercial apps within the last 24 months during which we’ve spent some 17.193,00 hours on Flutter projects.
12 min • May 16, 2024
When a project grows, sooner or later, a need for sharing logic across multiple clients and a server arises. At LeanCode, we completed a project that extensively employed logic sharing successfully. In this article, we highlight the steps and architecture decisions of the picked solution.