I am relatively new to flutter app development and therefore I am having issues implementing search on my app from the firestore cloudstore db. Currently I have the following code:
Widget build(BuildContext context) {
Future<DocumentSnapshot> search(String search) async {
List<DocumentSnapshot> bookList = (await Firestore.instance
.collection("book_data")
.where("booksearch", arrayContains: search)
.getDocuments())
.documents;
return List.generate(bookList.length, (int index) {
return bookList;
});
}
return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Padding(
padding: EdgeInsets.fromLTRB(15, 20, 15, 15),
child: SearchBar<List<DocumentSnapshot>>(
crossAxisCount: 1,
hintText: 'Search',
cancellationWidget: Icon(
Icons.close,
color: Colors.grey,
) ,
searchBarStyle: SearchBarStyle(
padding: EdgeInsets.all(2),
borderRadius: BorderRadius.circular(10),
),
iconActiveColor: Colors.white,
emptyWidget: Center(
child: Text("No results found! :(",
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
fontWeight: FontWeight.normal
),
),
),
icon: Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 0, 0),
child: Icon(
Icons.search,
color: Colors.grey,
),
),
textStyle: TextStyle(
color: Colors.white
),
onSearch: search,
onItemFound: ( bookList, int index) {
return ListTile(
title: Text(
bookList.bookname,
style: TextStyle(
color: Colors.white
),
),
subtitle: Text(
book.author,
style: TextStyle(
color: Colors.white
),
),
);
},
),
),
) ,
);
}
I actually want to compare the search query with the array having the label "booksearch" present in the "book_data" collection irrespective of which document it is in. Kindly help me with this.