I am getting this error in my code -> Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
I am using riverpod in my flutter project and doing some api call and the data which i am getting from api adding it to respective object through StateNotifierProvider and i am doing it in init state of the code.
When i swtich my screen in bottom navigation bar it is throwing this error.
Thanks in advance !!!
@override
void initState() {
checkPermission();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
ref.read(adminRepositoryProvider).getAllBooking().then((value) {
ref.read(bookingListProvider.notifier).changeData(value);
});
});
super.initState();
}
Whenever i switch my screen from one screen to another through bottom navigation bar it throws this error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe. E/flutter (10366): At this point the state of the widget's element tree is no longer stable. E/flutter (10366): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.