From a286dd5dd805529c3c5f07dacaae953831359b69 Mon Sep 17 00:00:00 2001 From: Dang Dat Date: Mon, 22 Dec 2025 17:01:26 +0700 Subject: [PATCH] [Memory leak] Remove listener and dispose --- .../scrolling_floating_button_animated.dart | 13 +++++-------- .../presentation/thread_detail_controller.dart | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/lib/presentation/views/floating_button/scrolling_floating_button_animated.dart b/core/lib/presentation/views/floating_button/scrolling_floating_button_animated.dart index a343389d5..49dbc012e 100644 --- a/core/lib/presentation/views/floating_button/scrolling_floating_button_animated.dart +++ b/core/lib/presentation/views/floating_button/scrolling_floating_button_animated.dart @@ -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 diff --git a/lib/features/thread_detail/presentation/thread_detail_controller.dart b/lib/features/thread_detail/presentation/thread_detail_controller.dart index 9468fab0e..bc9481f28 100644 --- a/lib/features/thread_detail/presentation/thread_detail_controller.dart +++ b/lib/features/thread_detail/presentation/thread_detail_controller.dart @@ -227,6 +227,7 @@ class ThreadDetailController extends BaseController { void reset() { emailIdsPresentation.clear(); + emailsInThreadDetailInfo.clear(); scrollController?.dispose(); scrollController = null; currentExpandedEmailId.value = null;