I Get It!

The last two functions above allow you to simply get a preference by its key without being concern with that preferences data type. The return data type for these functions is dynamic, and so the preference value will be returned in its own data type. Note, if the key doesn’t exist, a value of null is returned.

‘F’ is for Future

This class library as well as SharedPreferences library deals with ‘Future’ data types. You’ll see in this class library that those functions that return a ‘Future’ data type has the naming convention with a capital ‘F’ append on the end of the function’s name.

For Instance!

You’ll realize, within each async ‘get’ function in this class library that returns a ‘Future’ data type, you’re going to see one line again and again:

if (_prefsInstance == null) {

If there’s an ‘instance’ of SharedPreferences, the code is going to take advantage of it to retrieve the preference value — the init() function was called and instantiated an instance of SharedPreferences. Otherwise, the ‘await’ command is called again and again to get a required instance of the SharedPreferences:

var instance = await _prefs;

Since your app will be dealing with a finite list of preferences in most cases (typically when your app first starts up), the latency using the ‘await’ command will be tolerable. Try it (don’t call the init() function) and see for yourself.

Boolean

Supply a key string to these two functions, and you’ll get a Boolean value. If no key is found, a value of ‘false’ is returned.