I am trying to access my home page from the login screen, whenever i install the app for the first time and sign in, i get the following error:
"Exception has occurred. FlutterError (Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. 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.)"
The stack trace shows me that it is Databaseservice.addtokenId and the navigator.pushreplacementnamed that is causing the error. This is the snippet of code:
await PushNotificationsManager()
.init()
.then((token) async {
await DatabaseService(
uid: user.uid)
.addTokenId(token);
pr.hide();
Navigator.pushReplacementNamed(context, Routes.home);
})
This error occurs the first time i install the app, but not when i reload it for a few times.