From bb66f60829acae2fa3245f4ff7317758bc7cd862 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Fri, 18 Nov 2022 18:27:39 +0530 Subject: [PATCH] remove listeners properly --- .../expandable_menu_item_widget.dart | 10 ++++++---- lib/ui/viewer/file/file_caption_widget.dart | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/ui/components/expandable_menu_item_widget.dart b/lib/ui/components/expandable_menu_item_widget.dart index 5a75fae33..3c8ce203e 100644 --- a/lib/ui/components/expandable_menu_item_widget.dart +++ b/lib/ui/components/expandable_menu_item_widget.dart @@ -25,15 +25,13 @@ class _ExpandableMenuItemWidgetState extends State { final expandableController = ExpandableController(initialExpanded: false); @override void initState() { - expandableController.addListener(() { - setState(() {}); - }); + expandableController.addListener(_expandableControllerListener); super.initState(); } @override void dispose() { - expandableController.removeListener(() {}); + expandableController.removeListener(_expandableControllerListener); super.dispose(); } @@ -81,4 +79,8 @@ class _ExpandableMenuItemWidgetState extends State { ), ); } + + void _expandableControllerListener() { + setState(() {}); + } } diff --git a/lib/ui/viewer/file/file_caption_widget.dart b/lib/ui/viewer/file/file_caption_widget.dart index 91c75b4a9..b625ffa17 100644 --- a/lib/ui/viewer/file/file_caption_widget.dart +++ b/lib/ui/viewer/file/file_caption_widget.dart @@ -22,13 +22,7 @@ class _FileCaptionWidgetState extends State { @override void initState() { - _focusNode.addListener(() { - final caption = widget.file.caption; - if (_focusNode.hasFocus && caption != null) { - _textController.text = caption; - editedCaption = caption; - } - }); + _focusNode.addListener(_focusNodeListener); editedCaption = widget.file.caption; if (editedCaption != null && editedCaption!.isNotEmpty) { hintText = editedCaption!; @@ -42,7 +36,7 @@ class _FileCaptionWidgetState extends State { editFileCaption(null, widget.file, editedCaption); } _textController.dispose(); - _focusNode.removeListener(() {}); + _focusNode.removeListener(_focusNodeListener); super.dispose(); } @@ -107,4 +101,12 @@ class _FileCaptionWidgetState extends State { }, ); } + + void _focusNodeListener() { + final caption = widget.file.caption; + if (_focusNode.hasFocus && caption != null) { + _textController.text = caption; + editedCaption = caption; + } + } }