Using shared_preferences to read and write app data

There are several ways to save data onto a mobile device: you can persist data to a file, or you can use a local database, such as SQLite, or you can use SharedPreferences (on Android) or NSUserDefaults (on iOS).

shared_preferences should not be used for critical data as data stored there is not encrypted, and writes are not always guaranteed.

When using Flutter, you can take advantage of the shared_preferences library: it wraps both NSUserDefaults and SharedPreferences so that you can store simple data seamlessly in both iOS and Android without dealing with the specifics of the two operating systems.

Data is always persisted to disk asynchronously when you use shared_preferences.

SharedPreferences ...

Get Flutter Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.