I am working on a card game and it includes 2 parts.
- InputPage
- GamePage
In InputPage() user picks cards and it has a new game button. But if he/she not like the cards , he/she can be able to restart game. There is a restart game button in InputPage() , when user click on it, page must be completely restart. I did this with Navigator.of method. But when user go to GamePage(), i got an error like this:
Unhandled Exception: setState() called after dispose(): _GamePageState#d4518(lifecycle state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
I refresh the page with Navigator.pushReplacement..
Do you have any better idea?
This is the code :
FlatButton(
onPressed: () {
Navigator.of(context).pushReplacement(new MaterialPageRoute(
builder: (BuildContext context) => InputPage()));
},
