filterChanged method

dynamic filterChanged({
  1. bool reload = false,
})
inherited

Executa a pesquisa caso o texto seja diferente ou reload seja true

Implementation

filterChanged({bool reload = false}) {
  if (filter.text.trim() != searchText || reload) {
    searchText = filter.text.trim();
    if (searchText.isEmpty) {
      if (!confirmToLoadData) {
        list.clear();
        page = 1;
        setDataSource(offset: typeDiplay == 1 ? -1 : 0);
      }
    } else {
      /// Usa para guardar o valor original
      String tempSearchText = searchText;
      // Altera valor para false porque se o [onSubmittedSearch] não for chamado antes do delay a pesquisa por esta função será efetuada.
      _hasSearchedAlready = false;
      Future.delayed(
          Duration(milliseconds: selectModel!.dataSource.searchDelay), () {
        /// Só executa a pesquisa se o input não tiver mudado e já não tenha sido executada
        if (tempSearchText == filter.text.trim() && !_hasSearchedAlready) {
          list.clear();
          page = 1;
          setDataSourceSearch(
              offset: selectModel!.dataSource.supportPaginate
                  ? null
                  : typeDiplay == 1
                      ? -1
                      : 0);
          // Altera para true após fazer a pesquisa evitando que seja feita novamente caso o [onSubmittedSearch] seja chamado e
          //não tenha sido mudado o input [filter.text].
          _hasSearchedAlready = true;
        }
      });
    }
  }
}