I used a Future in the StatefulWidget, and the Future can still run then
after the StatefulWidget dispose
. When I need to change the StatefulWidget in then
, it is not safe.
My ideal situation should be that the StatefulWidget where the Future is located is cancelled after dispose. But I found that there is no way to cancel the Future. It has only three states: not completed
, completed with value
, and completed with error
.
Then I found a way to cancel the Future, but it is still not perfect, I have to use Stream or CancelableOperation.
Is there a better way to handle the life cycle of StatefulWidget and Future?