flutter: Fix AnimationController.reset() called after AnimationController.dispose() (WAR)
Reference: https://github.com/google/charts/issues/252
This commit is contained in:
parent
82733266f3
commit
e973a3f32b
|
@ -67,6 +67,7 @@ class _GamePageState extends State<GamePage>
|
||||||
);
|
);
|
||||||
late AnimationController _animationController;
|
late AnimationController _animationController;
|
||||||
late Animation animation;
|
late Animation animation;
|
||||||
|
bool disposed = false;
|
||||||
final String tag = "[game_page]";
|
final String tag = "[game_page]";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -119,11 +120,16 @@ class _GamePageState extends State<GamePage>
|
||||||
_animationController.addStatusListener((state) {
|
_animationController.addStatusListener((state) {
|
||||||
if (state == AnimationStatus.completed ||
|
if (state == AnimationStatus.completed ||
|
||||||
state == AnimationStatus.dismissed) {
|
state == AnimationStatus.dismissed) {
|
||||||
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_animationController.forward();
|
_animationController.forward();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_animationController.forward();
|
if (!disposed) {
|
||||||
|
_animationController.forward();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showTip(String? tip) {
|
showTip(String? tip) {
|
||||||
|
@ -173,6 +179,7 @@ class _GamePageState extends State<GamePage>
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disposed = false;
|
||||||
_animationController.duration =
|
_animationController.duration =
|
||||||
Duration(milliseconds: (Config.animationDuration * 1000).toInt());
|
Duration(milliseconds: (Config.animationDuration * 1000).toInt());
|
||||||
_animationController.reset();
|
_animationController.reset();
|
||||||
|
@ -485,7 +492,14 @@ class _GamePageState extends State<GamePage>
|
||||||
|
|
||||||
_animationController.duration =
|
_animationController.duration =
|
||||||
Duration(milliseconds: (Config.animationDuration * 1000).toInt());
|
Duration(milliseconds: (Config.animationDuration * 1000).toInt());
|
||||||
_animationController.reset();
|
|
||||||
|
if (!disposed) {
|
||||||
|
_animationController.reset();
|
||||||
|
} else {
|
||||||
|
print(
|
||||||
|
"[engineToGo] Disposed, so do not reset animationController.");
|
||||||
|
}
|
||||||
|
|
||||||
Game.instance.doMove(move.move);
|
Game.instance.doMove(move.move);
|
||||||
showTips();
|
showTips();
|
||||||
break;
|
break;
|
||||||
|
@ -1331,6 +1345,7 @@ class _GamePageState extends State<GamePage>
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
print("$tag dispose");
|
print("$tag dispose");
|
||||||
|
disposed = true;
|
||||||
widget.engine.shutdown();
|
widget.engine.shutdown();
|
||||||
_animationController.dispose();
|
_animationController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
Loading…
Reference in New Issue