Remove controllerListener on dispose

This commit is contained in:
David 2020-10-09 20:52:45 +02:00
parent 4d7cf69126
commit 114dc3dd50
1 changed files with 35 additions and 30 deletions

View File

@ -106,36 +106,8 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
_dragHeight = heightNotifier.value;
if (widget.controller != null) {
widget.controller.addListener(() {
switch (widget.controller.value.height) {
case -1:
_animateToHeight(
widget.minHeight,
duration: widget.controller.value.duration,
);
break;
case -2:
_animateToHeight(
widget.maxHeight,
duration: widget.controller.value.duration,
);
break;
case -3:
_animateToHeight(
0,
duration: widget.controller.value.duration,
);
break;
default:
_animateToHeight(
widget.controller.value.height.toDouble(),
duration: widget.controller.value.duration,
);
break;
}
});
}
if (widget.controller != null)
widget.controller.addListener(controllerListener);
super.initState();
}
@ -144,6 +116,10 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
void dispose() {
_heightController.close();
_animationController.dispose();
if (widget.controller != null)
widget.controller.removeListener(controllerListener);
super.dispose();
}
@ -349,6 +325,35 @@ class _MiniplayerState extends State<Miniplayer> with TickerProviderStateMixin {
animating = true;
_animationController.forward(from: 0);
}
void controllerListener() {
switch (widget.controller.value.height) {
case -1:
_animateToHeight(
widget.minHeight,
duration: widget.controller.value.duration,
);
break;
case -2:
_animateToHeight(
widget.maxHeight,
duration: widget.controller.value.duration,
);
break;
case -3:
_animateToHeight(
0,
duration: widget.controller.value.duration,
);
break;
default:
_animateToHeight(
widget.controller.value.height.toDouble(),
duration: widget.controller.value.duration,
);
break;
}
}
}
///-1 Min, -2 Max, -3 Dismiss