[Memory leak] Remove listener and dispose

This commit is contained in:
Dang Dat
2025-12-22 17:01:26 +07:00
committed by Dat H. Pham
parent 20b93cd8db
commit a286dd5dd8
2 changed files with 6 additions and 8 deletions
@@ -72,6 +72,7 @@ class _ScrollingFloatingButtonAnimatedState
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 250),
@@ -80,22 +81,19 @@ class _ScrollingFloatingButtonAnimatedState
lowerBound: 0,
upperBound: 120,
);
super.initState();
_handleScroll();
widget.scrollController?.addListener(_scrollListener);
}
@override
void dispose() {
widget.scrollController!.removeListener(() {});
widget.scrollController?.removeListener(_scrollListener);
_animationController.dispose();
super.dispose();
}
/// Function to add listener for scroll
void _handleScroll() {
void _scrollListener() {
ScrollController scrollController = widget.scrollController!;
scrollController.addListener(() {
if (scrollController.position.pixels > widget.limitIndicator! &&
if (scrollController.position.pixels > widget.limitIndicator! &&
scrollController.position.userScrollDirection ==
ScrollDirection.reverse) {
if (widget.animateIcon!) _animationController.forward();
@@ -114,7 +112,6 @@ class _ScrollingFloatingButtonAnimatedState
});
}
}
});
}
@override
@@ -227,6 +227,7 @@ class ThreadDetailController extends BaseController {
void reset() {
emailIdsPresentation.clear();
emailsInThreadDetailInfo.clear();
scrollController?.dispose();
scrollController = null;
currentExpandedEmailId.value = null;