Skip to content

Latest commit

 

History

History
44 lines (28 loc) · 1.26 KB

README.md

File metadata and controls

44 lines (28 loc) · 1.26 KB

A Flutter plugin that adds type safety when working with SharedPreferences.

The pure Android version can be found here.

pub package

Features

Adds type safety to avoid runtime crashes when working with the amazing shared_preferences package.

Usage

Create your Preference objects:

const intPreference = Preference<int>("integer", 3);

Set it's value:

intPreference.set(7);
//If you already have an instance of SharedPreferences, you should pass it:
intPreference.set(7, prefs: await SharedPreferences.getInstance());

And read it:

int currentPreferenceValue = await intPreference.get();

If you already have an instance of SharedPreference, you can synchronously read values:

SharedPreferences prefs = await SharedPreferences.getInstance();
int currentPreferenceValue = intPreference.getSync(prefs);

Additional information

This is the Flutter version of my Android Preftils package. You can read more about the reason behind this package here.