storage_wrapper 1.2.0 copy "storage_wrapper: ^1.2.0" to clipboard
storage_wrapper: ^1.2.0 copied to clipboard

outdated

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:

  • write
  • read
  • delete
  • containsKey

They all take the following parameters:

  • key: a String identifying the key of the value
  • iOptions: a IOSOptions object to specify iOS secure storage accessibility options
  • aOptions: a AndroidOptions object 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:

1
likes
0
pub points
65%
popularity

Publisher

verified publishermagicleon94.dev

A wrapper for shared_preferences and flutter_secure_storage that provides an unified api and a convenient mocking interface.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_secure_storage, shared_preferences

More

Packages that depend on storage_wrapper