closeAll static method

Future<void> closeAll()

Closes every box this registry has opened, and forgets the instances.

Why a consumer needs this. A teardown that calls the package-global Hive.close() closes the boxes in the GLOBAL registry, and the boxes opened here are not in it. They stay open over a directory the teardown then deletes, and the next open returns the cached box with its stale in-memory contents — a write appears to succeed and the read that follows returns the previous test's value. Nothing throws.

Call this instead of, or alongside, Hive.close() wherever storage is torn down and reopened in one process. ⚠️ Every store built from these instances holds its own reference to one, and this cannot reach them: after a close their hive field points at a closed instance, and the next box access throws. Storage is torn down as a unit — close the stores too, and build new ones on the way back up.

Implementation

static Future<void> closeAll() =>
    Future.wait(_byPath.keys.toList().map(_closeKey));