sraph_cache

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

sraph cache

Sraph Cache #

Base on shared_preferences and add listenable cache.
Usage #
To use this plugin, add sraph_cache as a dependency in your pubspec.yaml file.
Examples #
Here are small examples that show you how to use the API.
Write data
// init Cache.
await Cache.ensureInitialized();

// Save an integer value to 'counter' key.
await Cache.set<int>('counter', 10);
// Save an boolean value to 'repeat' key.
await Cache.set<bool>('repeat', true);
// Save an double value to 'decimal' key.
await Cache.set<double>('decimal', 1.5);
// Save an String value to 'action' key.
await Cache.set<String>('action', 'Start');
// Save an list of strings to 'items' key.
await Cache.set<List<String>>('items', <String>['Earth', 'Moon', 'Sun']);
copied to clipboard
Read data
// Try reading data from the 'counter' key. If it doesn't exist, returns null.
final int? counter = Cache.get<int>('counter');
// Try reading data from the 'repeat' key. If it doesn't exist, returns null.
final bool? repeat = Cache.get<bool>('repeat');
// Try reading data from the 'decimal' key. If it doesn't exist, returns null.
final double? decimal = Cache.get<double>('decimal');
// Try reading data from the 'action' key. If it doesn't exist, returns null.
final String? action = Cache.get<String>('action');
// Try reading data from the 'items' key. If it doesn't exist, returns null.
final List<String>? items = Cache.get<List<String>>('items');
copied to clipboard
Remove an entry
// Remove data for the 'counter' key.
final success = await Cache.remove('counter');
copied to clipboard
Listen to changes
return ValueListenableBuilder(
valueListenable: Cache.listenable(),
builder: (context, _, child) {
...
},
);
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.