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:math' as math;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,15 @@ 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;
|
||||
|
||||
controllerSubscription =
|
||||
widget.controller?.events.listen(_controllerListener);
|
||||
|
||||
_animationController = AnimationController(
|
||||
|
|
@ -65,6 +68,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
|||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
controllerSubscription?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue