Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter firebase querysnapshot: case insensitive method in dart code

I'm flutter user with firebase connected.

I'm trying to call list of users from cloud firestore with querysnapshot when users call search feature and then string submitted. What I've tried is snippet below:

Future<QuerySnapshot> allUsers = usersReference
    .where("profileName",
        isGreaterThanOrEqualTo: str)
    .getDocuments();
setState(() {
  futureSearchResults = allUsers;
});}

The problem is I have to make 'profileName' called by querysnapshot 'case insensitive'. For example, profileName 'HELLO WORLD' in cloud firestore must be printed as 'hello world' in my android studio flutter console. So i need a flutterFire method to convert all uppercase characters from cloud firestore to lowercase characters. Unfortunately, i couldn't find simple property to set case-insensitive from flutterFire plugIn.. ]:

Furthermore, what i'm trying to call from firestore is not a bunch of strings but certain form of document which is going to be converted to certain custom class written in dart. It made me unavailable with neat dart methods like toLowerCase().

If anyone know method in dart code to change uppercase characters from cloud firestore to lowercase, please share your knowledge.

Clear answers so appreciated!! Thank you in advance [:

like image 843
tsitixe Avatar asked Sep 17 '25 06:09

tsitixe


1 Answers

Firestore does not offer case-insensitive queries. If you need to query for strings using any case, you should store a "canonical" version of the string in Firestore, the make the client code use that for all queries. So, for example, you could store all strings as lowercase in the database, then require your client code to convert all strings to lowercase before querying.

like image 82
Doug Stevenson Avatar answered Sep 19 '25 20:09

Doug Stevenson