omni_kv_shared_preferences 0.1.0
omni_kv_shared_preferences: ^0.1.0 copied to clipboard
SharedPreferences adapter for the OmniKV framework.
OmniKV: SharedPreferences #
The official shared_preferences adapter for OmniKV.
Installation #
You must install both the adapter and the underlying storage package:
flutter pub add omni_kv omni_kv_shared_preferences shared_preferences
Quick Start #
Initialize your KvGateway with the SharedPreferencesKvAdapter:
import 'package:omni_kv/omni_kv.dart';
import 'package:omni_kv_shared_preferences/omni_kv_shared_preferences.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<void> main() async {
final prefs = await SharedPreferences.getInstance();
final kv = KvGateway(
SharedPreferencesKvAdapter(
prefs,
codec: const SharedPreferencesKvCodec(prefix: 'my_app.'),
),
);
// Ready to use!
}
Features & Limitations #
- Native Types: This adapter natively supports
String,int,double,bool, andList<String>. - Complex Types: To store custom objects, records, or maps, you must attach a
JsonConverter,ModelConverter, orRecordConverterto yourKvKey. - Scoped Clearing: If you provide a
prefixto the codec (e.g.,'my_app.'), callingkv.clear()will only delete keys that start with that prefix. Keys created by other packages will remain completely safe.
For full documentation on how to define keys and use the fluent API, see the core OmniKV package.