Shared Preferences are stored in XML format.

Shared Preferences is application specific, i.e. the data is lost on performing one of the following options:

on uninstalling the application

on clear the application data

Main use

The main use of Shared Preferences is to save user preferences, settings, maybe data (if not too large) so that next time the application is launched, these pieces of information could be retrieved and used.

Overview of the API

Full documentation can to be found in the Flutter packages repository .

1. Getters

Set < String > getKeys() :

Returns all keys

dynamic get(String key)

Returns the value, associated with the corresponding key

bool getBool(String key)

Returns the boolean value, associated with the corresponding key. If the value is not a boolean, throws an exception.

int getInt(String key)

Returns the integer value, associated with the corresponding key. If the value is not an integer, throws an exception.

double getDouble(String key)

Returns the double value, associated with the corresponding key. If the value is not a double, throws an exception.

String getString(String key)

Returns the string value, associated with the corresponding key. If the value is not a string, throws an exception.

List<String> getStringList(String key)

Returns a set of string values, associated with the corresponding key. If the value is not a string set, throws an exception.

2. Setters

Future < bool > setBool(String key, bool value)

Saves a boolean value and associated with the key.

Future < bool > setInt(String key, int value)

Saves an integer value and associated with the key.

Future < bool > setDouble(String key, double value)

Saves a double value and associated with the key.

Future < bool > setString(String key, String value)

Saves a string value and associated with the key.

Future < bool > setStringList(String key, List<String> value)

Saves a list of string values and associated with the key.

3. Removal

Future < bool > remove(String key)

Removes the key-pair associated with the key.

Also, in any setter, the fact of passing a null value, corresponds to calling a remove(key).

Future < bool > clear async

Removes all the key-pairs linked to the application package.