This recipe uses the following steps:

Add the dependency.

Save data.

Read data.

Remove data.

Note:
  To learn more, watch this short Package of the Week video on the shared_preferences package:

1. Add the dependency

Before starting, add the shared_preferences
plugin to the pubspec.yaml file:

dependencies

flutter

sdk

flutter

shared_preferences

<newest

version>"

2. Save data

To persist data, use the setter methods provided by the
SharedPreferences class. Setter methods are available for
various primitive types, such as setInt, setBool, and setString.

Setter methods do two things: First, synchronously update the
key-value pair in-memory. Then, persist the data to disk.