initialize method

Future<void> initialize({
  1. String? dir,
})

Initialize all storage boxes

Implementation

Future<void> initialize({String? dir}) async {
  if (_isInitialized) return;

  dir ??= (await getApplicationDocumentsDirectory()).path;
  Hive.init(dir);

  try {
    // Open all boxes
    _userBox = await Hive.openBox(userBox);
    _analyticsBox = await Hive.openBox(analyticsBox);
    _engagementBox = await Hive.openBox(engagementBox);
    _settingsBox = await Hive.openBox(settingsBox);

    _isInitialized = true;
    debugPrint('HiveStorageService initialized successfully');
  } catch (e) {
    debugPrint('Error initializing HiveStorageService: $e');
    rethrow;
  }
}