通过 Cloud Firestore 在我的 Flutter 应用程序上实现搜索时出现问题

Problem implementing search on my flutter app through cloud firestore

我想通过云 firestore 数据库(通过 'NAME' 文档字段)在我的 flutter 应用程序上实现搜索。我遇到了下面的查询,但遗憾的是这个查询区分大小写。 如果我想搜索 'Apple',那么我将不得不输入 'Apple'。输入 'apple' 或 'APplE' 不会给出任何结果。

FirebaseFirestore.instance
                        .collection('test')
                        .where(
                          'NAME',
                          isGreaterThanOrEqualTo: searchVal,
                          isLessThan: searchVal
                                  .substring(0, searchVal.length - 1) +
                              String.fromCharCode(searchVal
                                          .codeUnitAt(searchVal.length - 1) +
                                      1),
                        )
                        .snapshots()

请提出任何使此搜索高效且不区分大小写的方法。

根据这个相关 , Firestore cannot currently perform case-insensitive queries. In this case, the comment on your post applies, so you should create an alternate name field in Firestore that contains all lower case names. From the client side, all queries should be made lower case with a function such as toLowerCase() 使得字母大小写在两端完全匹配。