我正在编写一个函数来比较字符串是否包含关键字列表(字符串列表)我将它实现为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;
}