storage_wrapper 1.2.0
storage_wrapper: ^1.2.0 copied to clipboard
A wrapper for shared_preferences and flutter_secure_storage that provides an unified api and a convenient mocking interface.
Storage Wrapper #
A wrapper for shared_preferences and flutter_secure_storage that provides an unified api and a convenient mocking interface.
How it works #
Calling the StorageWrapper.common() constructor will return an instance that saves data in the SharedPreferences using the shared_preferences plugin.
Calling the StorageWrapper.secure() constructor will return an instance that saves data securely using the flutter_secure_storage plugin.
Once you got the instance, you can use the methods:
writereaddeletecontainsKey
They all take the following parameters:
key: aStringidentifying the key of the valueiOptions: aIOSOptionsobject to specify iOS secure storage accessibility optionsaOptions: aAndroidOptionsobject to specify Android secure storage accessibility options
While the AndroidOptions do not seem to be used by flutter_secure_storage, you can find more information about the IOSOptions here.
Mocking values for testing #
You can call the enableMock method passing an optional Map<String,String> for initial values. If nothing is passed, the storage will stay in mocking mode (the isMocking will be true) anyway but without any initial data, that will be defaulted to an empty Map<String,String>.
The mock data will not be persisted and each instance of StorageWrapper will not have the same mock data:
final mockWrapper = StorageWrapper.secure();
mockWrapper.enableMock();
final mockWrapper2 = StorageWrapper.secure();
mockWrapper2.enableMock({'foo':'bar'});
final anotherWrapper = StorageWrapper.secure();
//mockWrapper and mockWrapper2 will have different data sources
//anotherWrapper will not be a mock
Subsequent calls to enableMock will not have any effect.
You can always manipulate the data by accessing the mockEntries property.
More docs: #
The package wraps: