Question:
I’m using Hive in my Flutter project, and I encountered a strange issue:
• If I use "cache" as the box name, everything works fine without any errors.
• But when I use "users" as the box name, I get an error.
Example Code:
@override
Future<dynamic> load({required String key, String? boxName}) async {
await Hive.openBox(boxName!);
final box = Hive.box(boxName);
try {
final result = await box.get(key);
return result;
} catch (_) {
rethrow;
} finally {
box.close();
}
}
// Success case
final response = await _localStorage.load(
key: "products",
boxName: "cache",
);
// Error case
await _localStorage.save(
key: "users",
value: UserModel.toMapList(listProduct),
boxName: "users",
);
Insert the exact error message here, for example: “HiveError: Cannot open box ‘users’…”)
What I Tried:
• Changing the box name to something like "my_users" → It works
• Clearing the Hive database and reinstalling the app → No change
• Checking if "users" is a reserved keyword in Hive → Couldn’t find documentation on this
Question:
Why does "cache" work but "users" throws an error in Hive? Is "users" a restricted name in Hive, or is there another underlying issue?
Any insights would be greatly appreciated!