diff --git a/lib/src/widget/card_swiper.dart b/lib/src/widget/card_swiper.dart index 5d129ff..9eae6dd 100644 --- a/lib/src/widget/card_swiper.dart +++ b/lib/src/widget/card_swiper.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:collection'; import 'dart:math' as math; diff --git a/lib/src/widget/card_swiper_state.dart b/lib/src/widget/card_swiper_state.dart index 30a5925..6a38caf 100644 --- a/lib/src/widget/card_swiper_state.dart +++ b/lib/src/widget/card_swiper_state.dart @@ -20,13 +20,16 @@ class _CardSwiperState extends State bool get _canSwipe => _currentIndex != null && !widget.isDisabled; + StreamSubscription? controllerSubscription; + @override void initState() { super.initState(); _undoableIndex.state = widget.initialIndex; - widget.controller?.events.listen(_controllerListener); + controllerSubscription = + widget.controller?.events.listen(_controllerListener); _animationController = AnimationController( duration: widget.duration, @@ -65,6 +68,7 @@ class _CardSwiperState extends State @override void dispose() { _animationController.dispose(); + controllerSubscription?.cancel(); super.dispose(); }