openBox<V> method
Future<CollectionBox<V> >
openBox<V>(})
Implementation
@override
Future<CollectionBox<V>> openBox<V>(String name,
{bool preload = false,
implementation.CollectionBox<V> Function(String, BoxCollection)?
boxCreator}) async {
if (!boxNames.contains(name) && name != 'bad_keys') {
throw Exception('Box with name $name is not in the known'
'box names of this collection.');
}
final i = _openBoxes.indexWhere((box) => box.name == name);
if (i != -1) {
return _openBoxes[i] as CollectionBox<V>;
}
final boxIdentifier = name;
final box = boxCreator?.call(boxIdentifier, this) as CollectionBox<V>? ??
CollectionBox<V>(boxIdentifier, this);
if (preload) {
final hive = Hive as HiveImpl;
box._cachedBox = hive.isBoxOpen(box.name, this.name)
? hive.lazyBox(box.name, this.name)
: await hive.openBox(
box.name,
encryptionCipher: _cipher,
collection: this.name,
backend: _backends[name]!,
);
}
_openBoxes.add(box);
return box;
}