0

I just want to print "After Time" when my local time is greater than my Firebase data document, but it does nothing when my local time is greater only when I restart my application, it shows up print I want it right now displayed

ssaveTimeToFireStrone() async{

  await FirebaseFirestore.instance.collection("TimeToChange").doc("Time").set({
    "currentTime":atSixInEvening
  });
}


 Future getTheTime() async{
  final DocumentSnapshot doc=await FirebaseFirestore.instance.collection("TimeToChange").doc("Time").get();
  DateTime timeToTriggerEvent=doc["currentTime"].toDate();
  // await Future.delayed(Duration(seconds: 5));
  // print(timeToTriggerEvent);

  if(await DateTime.now().isAfter(timeToTriggerEvent)){
 
  print("after time");
  
 return true;

  }

 
}

1 Answers1

0

Thats because the Future is only called once (probably when you start the app). If you want to continously check if the time is after the trigger time then you have to put it in a loop. I would suggest a timer that checks once every second (so it doesn't cause any performance impact).

How to use the Timer: How to set an Interval in Flutter?

MindStudio
  • 706
  • 1
  • 4
  • 13