local_data_impl 0.0.4
local_data_impl: ^0.0.4 copied to clipboard
Local Data Impl is a Dart package that provides an easy-to-use abstraction for local data storage. It supports multiple storage backends, including Hive, SharedPreferences, and HydratedBloc, allowing [...]
Local Data Impl #
Local Data is a Dart package that provides a structured way to manage local data storage using Hive, SharedPreferences, and HydratedBloc.
Features #
- Hive Storage for structured key-value storage.
- SharedPreferences for simple key-value storage.
- HydratedBloc for state persistence.
- Memory Storage Interface for abstraction and flexibility.
Installation #
Add this to your pubspec.yaml:
dependencies:
local_data_impl: latest_version
Then, run:
dart pub get
Usage #
Register Local Data Services #
import 'package:local_data_impl/local_data_impl.dart';
import 'package:global/get_it_di.dart';
import 'package:shared_preferences/shared_preferences.dart';
void localDataServiceGetItRegister() async {
final SharedPreferences sharedPreferences =
await SharedPreferences.getInstance();
sl.registerLazySingleton(() => sharedPreferences);
sl.registerLazySingleton<IMemoryStorageService>(
() => CacheStorageServiceSharedPrefsImpl(prefs: sl()));
sl.registerLazySingleton<ILocalDataService>(
() => LocalDataServiceHydratedImpl());
}
Save Data #
final ILocalDataService localDataService = LocalDataServiceHydratedImpl();
await localDataService.addData(key: 'user', data: {'name': 'Alice', 'age': 25});
Retrieve Data #
final userData = await localDataService.getData(key: 'user');
print(userData); // Output: {name: Alice, age: 25}
Delete Data #
await localDataService.deleteData(key: 'user');
Supported Data Types #
StringintbooldoubleList<String>Map<String, dynamic>
License #
MIT License