gpt4 book ai didi

list - Flutter - 如何查询列表中的搜索项

转载 作者:IT老高 更新时间:2023-10-28 12:41:28 47 4
gpt4 key购买 nike

我想要 List<Food> 上的搜索请求我得到了。我使用过这样的查询方法:

_foodList.where((food) => food.name == userInputValue).toList();

但是,搜索要求我使用完整的文本和正确的文本大小写进行搜索。

如果我想处理 "dish" 的编译,该怎么办? ,然后是所有带有 "dish" 字样的食物名称将显示在 List ?

最佳答案

在比较之前将所有字符串小写或大写并使用 contains() 代替 ==:

_foodList.where((food) => food.name.toLowerCase().contains(userInputValue.toLowerCase()).toList();

如果值可以为 null,则需要添加额外的检查。

关于list - Flutter - 如何查询列表中的搜索项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54232385/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com