Home > Mobile >  Flutter Firebase where clause mixing between isNotEqualTo and isEqualTo clauses causes data to not s
Flutter Firebase where clause mixing between isNotEqualTo and isEqualTo clauses causes data to not s

Time:06-22

I'm still learning about Flutter with firebase.

So, I want to make a to-do-list (TDL) app, that can shows TDL item in the home page.

TDL can have 1 of these 3 status (selesai [finished], belum [not yet], telat [late]), and i wanted to show the ones which status is belum and telat, or simply the ones which status is not equal to selesai, and has the idProject equal to "0".

Simply i need to show TDL which has idProject = "0" and status!="selesai".

So i wrote this:

  static Stream<QuerySnapshot> getDataTDL() {
    return CToDoList
    .where("status",isNotEqualTo:"selesai")
    .where("idProject",isEqualTo: "0")
    .snapshots();
  }

enter image description here

here's a quick look on my data at firebase.. So, basically it should at least return this one -actually there's few more datas it can return- because it matched my where-clause requirements, but in fact it returns nothing at all.

So what can i do now?

CodePudding user response:

As your query contains both a not equal and an is equal comparison, you will have to create a composite index for the query. If you check the error logs of the flutter process, Firestore should give you a link you could use to create the index. If you can't find the link you would have to manually create it in the Firebase console for the project. More info is here.

  • Related