Skip to content

Commit 99b30ff

Browse files
ltOgtricardodalarme
authored andcommitted
cancel controller subscription on dispose
1 parent 8302627 commit 99b30ff

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/src/widget/card_swiper.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:collection';
23
import 'dart:math' as math;
34

lib/src/widget/card_swiper_state.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
2020

2121
bool get _canSwipe => _currentIndex != null && !widget.isDisabled;
2222

23+
StreamSubscription<ControllerEvent>? controllerSubscription;
24+
2325
@override
2426
void initState() {
2527
super.initState();
2628

2729
_undoableIndex.state = widget.initialIndex;
2830

29-
widget.controller?.events.listen(_controllerListener);
31+
controllerSubscription =
32+
widget.controller?.events.listen(_controllerListener);
3033

3134
_animationController = AnimationController(
3235
duration: widget.duration,
@@ -65,6 +68,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
6568
@override
6669
void dispose() {
6770
_animationController.dispose();
71+
controllerSubscription?.cancel();
6872
super.dispose();
6973
}
7074

0 commit comments

Comments
 (0)