fluttercommunity / flutter_workmanager

A Flutter plugin which allows you to execute code in the background on Android and iOS.
826 stars 247 forks source link

how to schedule task for every day at 12 AM ? #503

Closed SkJamirul closed 9 months ago

SkJamirul commented 9 months ago

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****

ened commented 9 months ago

The actual scheduling of a task is down to the operating system. You may encounter delays, or skipped tasks altogether.