0

I have a flutter app with Hive database. I have two pages in botton navigation bar. When i am on the first, it all works, all my CRUD operations. But when i go to second page and trying to return back, the box suddenly closes, because i get this error:

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

I open my hive box in main method:

void main() async {  


WidgetsFlutterBinding.ensureInitialized();



await Hive.initFlutter();   

Hive.registerAdapter(MeasurmentAdapter());

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

runApp(MyApp()); 

}

How can i fix this and navigate my pages without this?

leftjoin
  • 36,950
  • 8
  • 57
  • 116

1 Answers1

2

Check your SecondPage()

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

I accidentally insert this method in SecondPage()