Reputation: 291
I need help.. So am making like a store kinda app. Where item name are stored in a cloud fire store and I want user to be able to search on the home page what they are looking for.. So what is most cost and time efficient way to allow user to search the entire database .. For example if the word "Bike " is type I want to search the database for all items with the name bike..
But so its is cost efficient I don't want it to run for individual letters until the whole word is submitted.. So it won't query for..
B.. Then BI.. Then BIK.
Only fore bike when it is submitted.. Please any help..
Upvotes: 0
Views: 577
Reputation: 3737
Create a TextEditingController like:
TextEditingController _controller;
Then assign your textField with your controller:
TextField(controller: _controller);
Now, in the onPressed method of a button, get the text of the user:
FlatButton(child: Text('Search!'), onPressed: (){String textResult = _controller.text})
Then if you want to set up a query then just use:
Firestore.instance.collection('Vehicles').where('name', whereIn: _controller.text).snapshots();
Example of hardcoded data:
Firestore.instance.collection('Vehicles').where('name', whereIn: 'Bike').snapshots();
The snapshots() function will return all the data related to that search.
You can use a StreamBuilder to retrieve the data.
Upvotes: 1