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

Time:11-02

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:

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?

CodePudding user response:

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();
  • Related