最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mobile - Flutter Hive: boxName “cache” works, but “users” throws an error - Stack Overflow

programmeradmin1浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论