initialize static method

Future<void> initialize()

Initializes Hive and opens all registered box collections. Must be called before using any HHive instances.

Implementation

static Future<void> initialize() async {
  if (_alreadyInitialized) {
    return;
  }
  _alreadyInitialized = true;

  Hive.init(
    HIVE_INIT_PATH,
    backendPreference: HIVE_STORAGE_BACKEND_PREFERENCE,
  );

  // open box collections
  final List<String> boxes = [];
  bool anyUsesMeta = false;
  for (final config in HHImmutableConfig.instances.values) {
    boxes.add(config.env);
    if (config.usesMeta) {
      anyUsesMeta = true;
    }
  }
  // Single shared meta box for all environments
  if (anyUsesMeta) {
    boxes.add('_meta');
  }

  _hiveBoxCollection = await BoxCollection.open(
    _hiveBoxCollectionName,
    boxes.toSet(),
    path: HIVE_INIT_PATH,
    key: HIVE_CIPHER,
  );

  // Initialize web debug storage if available and enabled
  if (DEBUG_OBJ) {
    web_debug.initWebDebug();
  }
}