open static method
Future<BoxCollection>
open(
- String name,
- Set<
String> boxNames, { - String? path,
- @Deprecated('Use [cipher] instead') HiveCipher? key,
- HiveCipher? cipher,
- bool useLocks = true,
Implementation
static Future<BoxCollection> open(
String name,
Set<String> boxNames, {
String? path,
@Deprecated('Use [cipher] instead') HiveCipher? key,
HiveCipher? cipher,
bool useLocks = true,
}) async {
if (name.contains('/') || name.trim() != name || name.isEmpty) {
throw HiveError('Invalid collection name "$name"');
}
// compatibility for [key]
cipher ??= key;
final hive = Hive as HiveImpl;
if (!hive.wasInitialized && path != null) {
throw HiveError(
'You need to initialize Hive or '
'provide a path to store the box.',
);
}
final names = boxNames..add('bad_keys');
final backends = await hive.manager
.openCollection(names, path ?? hive.homePath, false, cipher, name);
final collection = BoxCollection(name, backends);
if (cipher != null) {
collection._cipher = cipher;
}
collection._badKeyBox = await collection.openBox<String>('bad_keys');
return collection;
}