I am returning a streamBuilder and inside the streamBuider, it returns a widget.
Now I have wrap a widget with dismissible so that I can delete the document from the collection from the cloud_firestore.
showingTheSelectedDateEvents() {
List<Widget> listViewContainer = [];
return StreamBuilder<QuerySnapshot>(
stream: firestoreInstance.collection('eventDetails').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.lightBlueAccent,
),
);
}
String theDatabaseDate;
final allDocuments = snapshot.data.docs;
//here we get all the documents from the snapshot.
for (var i in allDocuments) {
theDatabaseDate = i.data()['dateTime'];
if (theDatabaseDate == theDataProvider.databaseSelectedDate) {
print(theDatabaseDate +
" is same as " +
theDataProvider.databaseSelectedDate);
listViewContainer.add(Dismissible(
key: ObjectKey(snapshot.data.docs.elementAt(0)),
onDismissed: (direction) {
firestoreInstance
.collection("eventDetails")
.doc()
.delete()
.then((_) {
print("success!");
});
},
child://here
));
print(listViewContainer.length);
} else {
print("no any events for today");
}
}
return Expanded(
child: ListView(
reverse: true,
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 20.0),
children: listViewContainer,
),
);
},
);
}
I tried this for deleting the data from the cloud_firestore
key: ObjectKey(snapshot.data.docs.elementAt(0)),
onDismissed: (direction) {
firestoreInstance
.collection("eventDetails")
.doc()
.delete()
.then((_) {
print("success!");
});
},
I want to delete the specific document from the collection
I cannot figure out how to do that.
here is the database model

I am trying to delete the document of eventDetails collection.