Skip to content

Commit

Permalink
In dispose unregister from TextEditingController
Browse files Browse the repository at this point in the history
In dispose unregister from TextEditingController listeners,
otherwise the code might crash if the external TextEditingController
has a longer lifetime than the SearchableList.
  • Loading branch information
mariusSincovici authored and koukibadr committed Aug 21, 2024
1 parent a3bbb4a commit 2dfd72c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/searchable_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,13 @@ class _SearchableListState<T> extends State<SearchableList<T>> {
});
}
});
widget.searchTextController?.addListener(() {
filterList(widget.searchTextController?.text ?? '');
});
widget.searchTextController?.addListener(_textControllerListener);
}
@override
void dispose() {
scrollController.dispose();
widget.searchTextController?.removeListener(_textControllerListener);
super.dispose();
}
Expand Down Expand Up @@ -995,4 +994,8 @@ class _SearchableListState<T> extends State<SearchableList<T>> {
});
}
}
void _textControllerListener() {
filterList(widget.searchTextController?.text ?? '');
}
}

0 comments on commit 2dfd72c

Please sign in to comment.