remove listeners properly
This commit is contained in:
parent
264a7433fc
commit
bb66f60829
2 changed files with 16 additions and 12 deletions
|
@ -25,15 +25,13 @@ class _ExpandableMenuItemWidgetState extends State<ExpandableMenuItemWidget> {
|
|||
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<ExpandableMenuItemWidget> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _expandableControllerListener() {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|||
|
||||
@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<FileCaptionWidget> {
|
|||
editFileCaption(null, widget.file, editedCaption);
|
||||
}
|
||||
_textController.dispose();
|
||||
_focusNode.removeListener(() {});
|
||||
_focusNode.removeListener(_focusNodeListener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -107,4 +101,12 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _focusNodeListener() {
|
||||
final caption = widget.file.caption;
|
||||
if (_focusNode.hasFocus && caption != null) {
|
||||
_textController.text = caption;
|
||||
editedCaption = caption;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue