init method
void
init()
Implementation
void init() {
textColor = widget.textColor ?? Colors.grey[600];
_searchList = <T>[];
textController = widget.controller ?? textController;
notifier = ValueNotifier(null);
_focusNode = FocusNode();
isFocused = false;
_list = List<T>.from(widget.searchList);
_searchList.addAll(_list);
_focusNode.addListener(() {
if (!_focusNode.hasFocus) {
textController.clear();
overlaySearchList?.remove();
overlaySearchList = null;
} else {
_searchList
..clear()
..addAll(_list);
if (overlaySearchList == null) {
onTextFieldFocus(
circularIndicatorColor: widget.circularProgressIndicatorColor);
} else {
overlaySearchList?.markNeedsBuild();
}
}
});
textController.addListener(() async {
final text = textController.text;
if (text.trim().isNotEmpty) {
isLoading = true;
_searchList.clear();
final List<T?> filterList =
await widget.searchQueryBuilder(text, widget.searchList);
_searchList.clear();
_searchList.addAll(filterList);
isLoading = false;
if (overlaySearchList == null) {
onTextFieldFocus(
circularIndicatorColor: widget.circularProgressIndicatorColor);
} else {
overlaySearchList?.markNeedsBuild();
}
} else {
_searchList
..clear()
..addAll(_list);
if (overlaySearchList == null) {
onTextFieldFocus(
circularIndicatorColor: widget.circularProgressIndicatorColor);
} else {
overlaySearchList?.markNeedsBuild();
}
}
});
}