In my widget witch is a StatefulWidget, my logic check a token and in error case, I navigate to my home page.
I'm waiting the widget finish to build by using this method:
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.pushNamed(context, '/');
});
But the problem is that even if I'm not focus on this widget anymore, he will still run in background and make a redirection in loop.
In my logic, I use setState once if my accesToken is expired. After that the widget rebuild and I check with the new token send my server, and if he is empty I redirect my user to the home page. I think the problem come from the setState.
So, is there a way to kill or dispose this widget after leaving ? Or maybe an other way to navigate ?