Flutter:将字符串与列表进行比较 回调不起作用

问题描述 投票:0回答:1

我正在编写一个函数来比较字符串是否包含关键字列表(字符串列表)我将它实现为flutter中另一个小部件的回调函数。回调函数有效,但是,回调函数内部的compare方法不起作用。

请发送帮助/。\

  void callback(List<String> filterKeyword) {
    setState(() {
      this.filterKeyword = filterKeyword;
    });
    resFiltered.clear();
    res.forEach((res) {
      if (compareString(res.type, this.filterKeyword)) {
        resFiltered.add(res);
      }
    });
  }

  bool compareString(String inputStr, List<String> items) {
    if (items.length == 0) {
      return true;
    }
    for(int i = 0; i < items.length; i++) {
      if(inputStr.contains(items[i])) {
        return true;
      }
    }
    return false;
  }
string flutter dart callback google-cloud-firestore
1个回答
0
投票

我做了一点点改变,以返回字符串,并实现了添加到flutter默认项目中作为文本小部件。而且有效。您必须确保参数是否确实如您所写...我注意到这是区分大小写的...

enter image description here

我希望它会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.