sedatg
sedatg

Reputation: 51

How can I search based on relevance to flutter?

How can I search based on relevance to flutter? I'm not just talking about displaying the searched data. I am talking about the ones closest to the term to be searched in terms of their letters to the top. Normally the index order with listviewbuilder is 1,2,3 ... normally. But if the search term is closest to the word having the 2nd id among the data, I want the order to change to 2, 1, 3. How can I achieve this?

the codes I tried

 _dataResults = _dataList.where((a) {
        return (a.data_name.contains(controller.text) ||
            a.data_name.toLowerCase().contains(controller.text) ||
            a.data_name.toUpperCase().contains(controller.text) ||
            a.data_name.startsWith(controller.text) ||
            a.data_name.endsWith(controller.text) ||
            a.data_title.contains(controller.text) ||
            a.data_title.toLowerCase().contains(controller.text) ||
            a.data_title.startsWith(controller.text) ||
            a.data_title.endsWith(controller.text) ||
            a.data_description.contains(controller.text) ||
            a.data_description.toLowerCase().contains(controller.text) ||
            a.data_description.startsWith(controller.text) ||
            a.data_description.endsWith(controller.text));
      }).toList();

Upvotes: 0

Views: 99

Answers (0)

Related Questions