I'm trying to check if any document from my collection contains a Value with a specificTime. But Im doing something wrong.
Im searching for a way to check if any Document in my Collection contains the "DateTime.now().year" in the "CreatedAt" Field.
List documents = [];
@override
void initState() {
Firestore.instance.collection('Collection').getDocuments().then((snapshot) {
List<DocumentSnapshot> allDocs = snapshot.documents;
List<DocumentSnapshot> yearDocs = allDocs.where((e) => e.data['createdAt'].toDate.year() == DateTime.now().year).toList();
// iterate over your yearDocs, and add the data to documents
yearDocs.forEach((item){
documents.add(item);
});
});
super.initState();
}
I want to set a List with Documents where the "Field" contains the "DateTime.now().year". Then i check if the List is emtpty.
documents.length >= 1? Container(
child: Text('works'),
) : SizedBox(),