【问题标题】:Hive box closes after route navigation路线导航后蜂巢箱关闭
【发布时间】:2021-08-27 08:23:23
【问题描述】:

我有一个带有 Hive 数据库的颤振应用程序。我在底部导航栏中有两个页面。当我在第一个时,一切正常,我所有的 CRUD 操作。但是当我转到第二页并试图返回时,框突然关闭,因为我收到此错误:

Box not found. Did you forget to call Hive.openBox()?

我在 main 方法中打开我的蜂箱:

void main() async {  


WidgetsFlutterBinding.ensureInitialized();



await Hive.initFlutter();   

Hive.registerAdapter(MeasurmentAdapter());

 await Hive.openBox<Measurment>('measurments');   

runApp(MyApp()); 

}

如果没有这个,我该如何解决这个问题并浏览我的页面?

【问题讨论】:

    标签: flutter android-studio dart flutter-hive


    【解决方案1】:

    检查您的 SecondPage()

     void dispose() {
        Hive.close();
        super.dispose();
       }
    

    我不小心在 SecondPage() 中插入了这个方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 2017-01-20
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多