I want to build a flutter app which will show notification when it's time for prayer. From a api I'm getting the prayer time. And with awesome_notification package I'm showing notification for a certain time. Now I have created a function from where it will return the time.
dateTimeFormat() async {
if (DateFormat('hh:mm').format(DateTime.now()) ==
_prayerRes.mainData.first.timings.asr.substring(0, 5)) {
namajName = "Asar";
return _prayerRes.mainData.first.timings.asr.substring(0, 5);
} else if (DateFormat('hh:mm').format(DateTime.now()) ==
_prayerRes.mainData.first.timings.dhuhr.substring(0, 5)) {
namajName = "Johar";
return _prayerRes.mainData.first.timings.dhuhr.substring(0, 5);
} else if (DateFormat('hh:mm').format(DateTime.now()) ==
_prayerRes.mainData.first.timings.fajr.substring(0, 5)) {
namajName = "Fazar";
return _prayerRes.mainData.first.timings.fajr.substring(0, 5);
} else if (DateFormat('hh:mm').format(DateTime.now()) ==
_prayerRes.mainData.first.timings.isha.substring(0, 5)) {
namajName = "Isha";
return _prayerRes.mainData.first.timings.isha.substring(0, 5);
} else if (DateFormat('hh:mm').format(DateTime.now()) ==
_prayerRes.mainData.first.timings.maghrib.substring(0, 5)) {
namajName = "Magrib";
return _prayerRes.mainData.first.timings.maghrib.substring(0, 5);
}
// else if (DateFormat('hh:mm').format(DateTime.now()) == "09:52" )
// {
// return "09:52";
// }
// else if (DateFormat('hh:mm').format(DateTime.now()) == "09:53" )
// {
// return "09:53";
// }
else if (DateFormat('hh:mm').format(DateTime.now()) == "10:25" )
{
if (kDebugMode) {
print("testing ================= ${DateFormat('hh:mm').format(DateTime.now())}");
}
return "10.25";
}
if (kDebugMode) {
print("testing2 ================= ${DateFormat('hh:mm').format(DateTime.now())}");
}
else
{
return "10:26";
}
}
Now the problem is when I call this function it always returning the else statement and it only works one time. I need to trigger this function when I it's time for prayer and returning the prayer time. How to do that in flutter?