Files
iiEsaywebUIapp/lib/core/persistence/hive_bootstrap.dart
cogwheel0 80129c5711 chore: integrate Hive for local storage management
- Added `hive_ce` and `hive_ce_flutter` dependencies for enhanced local storage capabilities.
- Refactored the main application to initialize Hive and migrate existing data.
- Updated storage service implementations to utilize Hive for managing application settings and task queues.
- Removed the deprecated `StorageService` class to streamline the codebase and improve maintainability.
2025-10-01 16:55:44 +05:30

47 lines
1.2 KiB
Dart

import 'package:hive_ce_flutter/hive_flutter.dart';
import 'hive_boxes.dart';
/// Sets up Hive and exposes lazily opened boxes used across the app.
class HiveBootstrap {
HiveBootstrap._();
static final HiveBootstrap instance = HiveBootstrap._();
HiveBoxes? _boxes;
/// Ensures Hive is initialized and all required boxes are open.
Future<HiveBoxes> ensureInitialized() async {
if (_boxes != null) {
return _boxes!;
}
await Hive.initFlutter('conduit_hive');
final preferences = await Hive.openBox<dynamic>(HiveBoxNames.preferences);
final caches = await Hive.openBox<dynamic>(HiveBoxNames.caches);
final attachmentQueue = await Hive.openBox<dynamic>(
HiveBoxNames.attachmentQueue,
);
final metadata = await Hive.openBox<dynamic>(HiveBoxNames.metadata);
_boxes = HiveBoxes(
preferences: preferences,
caches: caches,
attachmentQueue: attachmentQueue,
metadata: metadata,
);
return _boxes!;
}
/// Access the cached boxes after [ensureInitialized] has completed.
HiveBoxes get boxes {
final cached = _boxes;
if (cached == null) {
throw StateError('HiveBootstrap.ensureInitialized must run first.');
}
return cached;
}
}