Home > front end >  Fetch flutter firebase doc on a specific date
Fetch flutter firebase doc on a specific date

Time:10-13

I have a firebase doc where i want to fetch data on a specific date. For example I wrote a data today and I want to fetch it on 14/10/22. How can I do that??Please help

CodePudding user response:

As I understand it from your question even if you wrote data today you want to fetch it at some other time right ? so here is my solution when you wrote a data pick a data that you want to fetch at the filter it using where Boolean method

CodePudding user response:

add a timeStamp field in the doc with the date you want. then every time you enter the app check if this timeStamp equals today`s date.

you can get today`s date by getting the current date of the device.

DateTime currentDate = DateTime.now();

or you can use ntp package for getting the internet current date, and this way is better in case device`s date is not correct.

DateTime startDate = await NTP.now();

and after fetching the timeStamp field from firestore make sure to convert it to DateTime so you can compare between the two DateTime objects.

var dateFromFirestore = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);

then when the app starts check if the current date equals to the timeStamp from firestore doc field.

i hope you reach what you want. see this example.

  • Related