【问题标题】:Using Hive.box("user") throws the error The box "user" is already open and of type Box<User>使用 Hive.box("user") 会引发错误框“user”已打开且类型为 Box<User>
【发布时间】:2021-07-21 16:21:33
【问题描述】:

我知道有人问过这个问题before,但解决方案对我没有帮助。根据蜂巢文档,当我在我的代码中尝试这个时,可以像这样调用一个打开的盒子Hive.box('myBox'); 我得到错误

The box "user" is already open and of type Box<User>.

任何人都知道为什么会发生这种情况。

【问题讨论】:

    标签: flutter flutter-hive


    【解决方案1】:

    试试这个

    void stuff() async {
      //Hive.init('somePath') 
    
      var box = await Hive.openBox('user');
    
      box.put('name', 'David');
      
      print('Name: ${box.get('name')}');
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-18
      • 2022-01-03
      • 2010-09-14
      • 2023-01-25
      • 2019-02-06
      • 2021-10-02
      • 1970-01-01
      • 2013-12-15
      • 2021-08-20
      相关资源
      最近更新 更多