how to schedule task for every day at 12 AM ?
SkJamirul opened this issue · comments
final tomorrowMidnight = DateTime( now.year, now.month, now.day + 1, 0, 0); // Midnight of the next day
final initialDelay = tomorrowMidnight.isBefore(now) ? tomorrowMidnight.add(const Duration(days: 1)).difference( now) // If it's already past midnight, schedule for the next day
: tomorrowMidnight.difference(now);
Workmanager().initialize(callbackDispatcher);
Workmanager().registerPeriodicTask( "newtask",
"CheckTask",
initialDelay: initialDelay,
frequency: const Duration(days: 1) // Run daily );
that's not working****
The actual scheduling of a task is down to the operating system. You may encounter delays, or skipped tasks altogether.