I want to create a search functionality for my project to fetch data from firestore. I am trying to create a Flutter search that searches documents from Firebase, but I am getting the error below:
The getter 'documents' isn't defined for the type 'QuerySnapshot'. Try importing the library that defines 'documents', correcting the name to the name of an existing getter, or defining a getter or field named 'documents'.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:nethouese/pages/views/service2/searchService.dart';
class search extends StatefulWidget {
@override
_searchState createState() => _searchState();
}
class _searchState extends State<search> {
TextEditingController _searchController= TextEditingController();
var QueryResult=[];
var tempsearchstore=[];
@override
void initialSearch(String value) {
if(value.length==0){
setState(() {
QueryResult=[];
tempsearchstore=[];
});
}
var capitalizedValue=value.substring(0,1).toUpperCase()+value.substring(1);
if(QueryResult.length==0&& value.length==1){
SearchService().searchByName(value).then((QuerySnapshot docs){
//Below are the two lines of code where the error is occurring.
for(int i=0;i<QuerySnapshot.documents.length)
QueryResult.add(docs.documents[i].data);
});
}
}
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Text('serch bar'),
TextField(
onChanged: (value){
initialSearch(value);
},
controller: _searchController,
decoration: InputDecoration(
prefixIcon: IconButton(
color: Colors.black,
icon: Icon(Icons.arrow_back),
iconSize: 20.0,
onPressed:(){
Navigator.of(context).pop();
},
)
),
)
],
),
);
}
}
Below is a screenshot of the lines of code where the error is occuring:
i also get the same Error even if i chaged QuerySnapshot to DocumentSnapshot enter image description here
