cancel controller subscription on dispose
This commit is contained in:
parent
8302627616
commit
99b30ff2d4
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,16 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
||||||
|
|
||||||
bool get _canSwipe => _currentIndex != null && !widget.isDisabled;
|
bool get _canSwipe => _currentIndex != null && !widget.isDisabled;
|
||||||
|
|
||||||
|
StreamSubscription<ControllerEvent>? controllerSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_undoableIndex.state = widget.initialIndex;
|
_undoableIndex.state = widget.initialIndex;
|
||||||
|
|
||||||
widget.controller?.events.listen(_controllerListener);
|
controllerSubscription =
|
||||||
|
widget.controller?.events.listen(_controllerListener);
|
||||||
|
|
||||||
_animationController = AnimationController(
|
_animationController = AnimationController(
|
||||||
duration: widget.duration,
|
duration: widget.duration,
|
||||||
|
|
@ -65,6 +68,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_animationController.dispose();
|
_animationController.dispose();
|
||||||
|
controllerSubscription?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue