'firestore keyword working in the code in flutter
Hi guys i am trying write firestore.instance but it give error. I can not under stand why this error occur in the below code.
void _fetchMarkersFromDb() {
// TODO: improve this
print('_fetchMarkersFromDb() called');
***Firestore***.instance.collection('markers').getDocuments().then((docs) async {
final docLength = docs.documents.length;
final clients = List(docLength);
for (int i = 0; i < docLength; i++) {
clients[i] = docs.documents[i];
}
if (!isFirstCycle && isMyMarkerFetched) {
currentLocation = await Geolocator.getCurrentPosition();
}
_populateMarkers(clients);
});
}
Solution 1:[1]
Use FirebaseFirestore instead.
Like:
FirebaseFirestore.instance.collection('markers').get().then((value) async {
var docs = value.docs;
final docLength = docs.length;
final clients = List(docLength);
for (int i = 0; i < docLength; i++) {
clients[i] = docs[i];
}
if (!isFirstCycle && isMyMarkerFetched) {
currentLocation = await Geolocator.getCurrentPosition();
}
_populateMarkers(clients);
});
To delete a document use:
FirebaseFirestore.instance.collection('markers').doc(documentId).delete()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
