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?