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
Libraries
- config/di/register_local_data_hive_data_source_service_get_it_di
- data/data_sources/hive_storage_service_impl
- data/data_sources/i_data_sources/i_hive_storage_service
- data/data_sources/i_data_sources/i_local_data_service
- data/data_sources/i_data_sources/i_memory_storage_service
- data/data_sources/local_data_service_hive_data_source_impl
- data/data_sources/local_data_service_hydrated_impl
- data/data_sources/local_data_service_memory_storage_data_source_impl
- data/data_sources/memory_storage_service_hive_impl
- enum/data_type
- local_data_impl