简体   繁体   中英

Flutter Dart Search List

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.

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM