From 99b30ff2d4fe33d68cffd32f66b6ba974533733c Mon Sep 17 00:00:00 2001 From: ltOgt Date: Sat, 17 Aug 2024 11:28:38 +0200 Subject: [PATCH] cancel controller subscription on dispose --- lib/src/widget/card_swiper.dart | 1 + lib/src/widget/card_swiper_state.dart | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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(); }