简体   繁体   English

Flutter Dart 搜索列表

[英]Flutter Dart Search List

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

I have a list of about 70-80 words.我有一个大约 70-80 个单词的列表。 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 ?如何在Flutter / Dart中做到这一点?

For example if I type 'tec', the Techonology topic should be the result.例如,如果我输入“tec”,则应该是Techonology主题。 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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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