0
List<String> topics = [
  'Photography',
  'News',
  'Facts',
  'How-to',
  'Technology',
  'Science',
  'Space',
];

I have a list of about 70-80 words. I want to search this list and make it searchable even if a spelling mistake is made. The list is also case-sensitive. No UI needed.
How can I do it in Flutter/Dart?

For example if I type 'tec', the Techonology topic should be the result. The topics are case sensitive, but the query should handle this too.

3
  • 3
    You need to specify a lot more requirements and come with some examples. What do you define as "spelling mistake" (are e.g. case problems also spelling mistakes)? Should the code come with multiple candidates for words which could be correct? What have you done to solve the problem yourself? Commented Dec 31, 2020 at 16:37
  • What have you tried? Have you taken a look at: google.com/search?q=search+through+a+list+flutter ? The list cannot be searchable even if there is a spelling mistake. For that you would have to use a search engine like algolia or elasticsearch. I would personally not implement the searching even if there is a spelling mistake because it is expensive to use the above search engines. Commented Dec 31, 2020 at 16:48
  • 1
    This might be hepful blog.usejournal.com/flutter-search-in-listview-1ffa40956685 Commented Dec 31, 2020 at 19:06

1 Answer 1

2

Try below one

List<String> topics = [
  'Photography',
  'News',
  'Facts',
  'How-to',
  'Technology',
  'Science',
  'Space',
];
  
 var text='ence';
 var _searchResult = topics.where(
                    (topics) => (topics.contains(text) || 
                    topics.toLowerCase().contains(text))
                );
  
 print(_searchResult.toString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.