【问题标题】:How to do a query search in Dart?如何在 Dart 中进行查询搜索?
【发布时间】:2021-07-26 04:18:26
【问题描述】:

我需要在列表中按查询进行搜索

像这样:

final List<String> products = ['apple', 'ball', 'mouse', 'smartphone'];

List<String> search(){
    //All the code
}

【问题讨论】:

标签: arrays dart search


【解决方案1】:
List<String> products = ['apple', 'ball', 'mouse', 'smartphone']; 


List<String> search(String inputText){
    //All the code

    var result = products.where((product) =>
      product.toLowerCase().contains(inputText.toLowerCase());

    return result;
    
}

【讨论】:

    猜你喜欢
    • 2013-04-29
    • 1970-01-01
    • 2019-07-05
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2013-09-03
    • 1970-01-01
    相关资源
    最近更新 更多