initialize method

  1. @override
Future<HiveLocalAdapter<T>> initialize()
override

Implementation

@override
Future<HiveLocalAdapter<T>> initialize() async {
  if (isInitialized) return this;
  final hive = _hiveLocalStorage.hive;

  if (!hive.isBoxOpen(internalType)) {
    if (!hive.isAdapterRegistered(typeId)) {
      hive.registerAdapter(this);
    }
  }

  try {
    if (_hiveLocalStorage.clear == LocalStorageClearStrategy.always) {
      await _hiveLocalStorage.deleteBox(internalType);
    }
    _box = await _hiveLocalStorage.openBox<T>(internalType);
  } catch (e, stackTrace) {
    print('[flutter_data] Box failed to open:\n$e\n$stackTrace');
  }

  return this;
}