Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I query on the Flutter app for products added to Firebase today

I am trying to develop a stock management application on Flutter. I have integrated Firebase into the app and I can view the data on the app. My collection and documents are as follows:

enter image description here

There are products added on different dates in the database, but I want to filter the products added today. No products are found when I type a query like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

var response = await FirebaseFirestore.instance
    .collection('sayim')
    .where('sirket', isEqualTo: sirket)
    .where('tarih', isLessThanOrEqualTo: DateTime.now())
    .where('tarih', isGreaterThanOrEqualTo: DateTime.now().day - 1)
    .get();

I want to list all the products from the beginning of the day until now. How should I edit the query?

>Solution :

Just create a new date from now

   DateTime now = new DateTime.now();
   DateTime date = new DateTime(now.year, now.month, now.day); 

and use that in your query

 var response = await FirebaseFirestore.instance
.collection('sayim')
.where('sirket', isEqualTo: sirket)
.where('tarih', isLessThanOrEqualTo: now)
.where('tarih', isGreaterThanOrEqualTo: date)
.get();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading