Skip to content

Commit

Permalink
cancel controller subscription on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
ltOgt authored and ricardodalarme committed Oct 8, 2024
1 parent 8302627 commit 99b30ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/src/widget/card_swiper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:collection';
import 'dart:math' as math;

Expand Down
6 changes: 5 additions & 1 deletion lib/src/widget/card_swiper_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>

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

StreamSubscription<ControllerEvent>? 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,
Expand Down Expand Up @@ -65,6 +68,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
@override
void dispose() {
_animationController.dispose();
controllerSubscription?.cancel();
super.dispose();
}

Expand Down

0 comments on commit 99b30ff

Please sign in to comment.