Local Data is a Dart package that provides a structured way to manage local data storage using Hive, SharedPreferences, and HydratedBloc.
- Hive Storage for structured key-value storage.
- SharedPreferences for simple key-value storage.
- HydratedBloc for state persistence.
- Memory Storage Interface for abstraction and flexibility.
Add this to your pubspec.yaml:
dependencies:
local_data_impl: latest_versionThen, run:
dart pub getimport '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());
}final ILocalDataService localDataService = LocalDataServiceHydratedImpl();
await localDataService.addData(key: 'user', data: {'name': 'Alice', 'age': 25});final userData = await localDataService.getData(key: 'user');
print(userData); // Output: {name: Alice, age: 25}await localDataService.deleteData(key: 'user');StringintbooldoubleList<String>Map<String, dynamic>
MIT License