0

How can I do instant search in Flutter Firebase?

For example I have Brands list in my Firebase Documents like this; Brands Doc

and I want to do Search instantly in list for example when I text "F" I want to display Ford and Fiat or when I text "Te" I want to display Tesla. So whatever I type in the search bar, I want the strings containing those words or letters to appear on the screen.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rkdio
  • 153
  • 2
  • 13

1 Answers1

1

You are looking for this one

Here is the sample of query, (You can create by your own way)

List<DocumentSnapshot> documentList = (await Firestore.instance
        .collection("cases")
        .document(await firestoreProvider.getUid())
        .collection(caseCategory)
        .where("caseNumber", arrayContains: query) // query param will be your search string
        .getDocuments())
    .documents;
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • It's a working solution, but I need to enter all possible variables into the database beforehand. If I want to view Tesla, I need to enter T, Te, Tes, Tesl, Tesla data for Tesla. It's too long for me to do this for every brand and when the database is updated every time, I also need to do it. – Rkdio Aug 04 '21 at 12:25
  • I think it should have a dynamic solution – Rkdio Aug 04 '21 at 12:26
  • It will count transaction for every query so better to get all the values in one list and try to filter data from List. – Pratik Butani Aug 04 '21 at 12:45