talira

shared_preferences

Flutter plugin for storing simple key-value settings on the device

open sourceBSD-3-Clausefree

shared_preferences is the Flutter team's plugin for reading and writing simple key-value pairs (ints, doubles, bools, strings and string lists) in each platform's own preferences store: NSUserDefaults on iOS and macOS, DataStore Preferences or SharedPreferences on Android, and the equivalents on Linux, Windows and the web. Since 2.3 it has three APIs: the original SharedPreferences, SharedPreferencesAsync, which always reads the platform store, and SharedPreferencesWithCache, which allows synchronous reads after loading. Writes may reach disk asynchronously, so it isn't for critical data. It's part of the flutter/packages repository and published on pub.dev by flutter.dev.

Problems it solves

  • save a user's settings like dark mode on the device in a Flutter app
  • remember small values between launches of my Flutter app on Android and iOS
  • store simple key-value data in a Flutter web or desktop app

Features

  • Stores simple key-value settings on the device from Flutter
  • Uses each platform's preferences store (NSUserDefaults, DataStore, and others)
  • Android, iOS, Linux, macOS, web and Windows
  • Async and cached APIs

Limitations

  • Writes may be persisted to disk asynchronously with no guarantee, so it must not be used for critical data1

Alternatives

The same job

These do what shared_preferences does.

  1. Flutter Packages Flutter's first-party packages and plugins, maintained by the Flutter team
  2. flutter_secure_storage Flutter plugin that stores secrets in each platform's secure storage
  3. path_provider Flutter plugin for finding commonly used locations on the device's file system
  4. Location (Flutter) Real-time device location for Flutter on every platform

Compare shared_preferences with the top 3