Flutter - Schedule Task Using Cron Job Scheduler [2022]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to effortless code learning i hope you are doing well in this video you will learn how to schedule and cancel your tasks using cron job you will also learn about cron expression in detail and at the end of the video you will be able to figure out when to use cron job and when to go for the alternative of the crown job so let's begin and make sure to watch the video till the end so first of all let's understand what is mean by schedule tasks schedule tasks is the task which will be executed in the future for example phone memory cleanup or take backup of phone data to cloud these are schedule tasks and can be executed based on the certain intervals maybe daily weekly or monthly to schedule tasks using cron job i will be using cron package it is really easy and no configuration is required to use this package now let's make changes into main.dart file so first of all i will define object of cron class now let's create method which will schedule tasks i will be calling schedule method of crown class here we need to specify cron expression and here we need to specify the callback method which will be executed once this event is triggered so here i will just print message i will print time so here we have specified crown expression so this task will be executed after every one minute this each character in this chronic expression is called sub expression you can specify 5 or 6 of the expression inside this cron expression here you can see i have specified 6 of the expression so if you specify 6 of the expression this crown expression starts from second and if you specify us of expression then this chronic expression starts from minute and each sub expression have meaning the first sub expression is for second seconds of expression for minute third is for hour fourth is for day of month fifth is for month and last is for day of week for the second and minute possible value is between 0 to 59 here if you see this slash is specified the meaning of this slash is called step this value will be incremented by the value specified after the slash here minute will be incremented after every one minute likewise you can specify any value here for example 3 so this minute value will be incremented after every 3 minute for our possible values are between 0 to 23 for day of month possible values are between 1 to 31 based on the last working dog month for month possible values are between 1 to 12 also you can specify name of month like jan or pape here meaning of this comma means this task will be executed in jan and pape month likewise you can specify multiple values if you want to execute this task in april month also you can specify april here so by using comma we can specify the possible values for day of money you can specify values between 1 to 7 or you can specify name of the day like monday to friday this hyphen is used for range here we have specified this task should be executed every day between monday to friday and it won't execute it on saturday and sunday now for testing purpose i want to execute this task for every one minute so let's change the crown expression and test now i am calling this method from schedule button now let's check here you can see the time is printed now this task should be executed after another minute here i am fast forwarding the video here you can see the task is executed after minute so far we have scheduled tasks now let's add code to cancel the schedule task so task will be cancelled on click of this cancel button so for that i will be writing method to cancel task i will need object of schedule task which is written from this schedule method so first of all let's define variable of type schedule tasks and let's assign value written from the schedule method to this variable now i will be using this schedule task variable to cancel task on this schedule task instance i will be calling cancel method which will cancel the schedule task now let's call this method from cancel button now let's cancel the task now this task should not be executed here i am fast forwarding the video and we will see if this task should get cancelled so here you can see the task is cancelled and nothing is printed from the long time that's how we can schedule and cancel the tasks using cron job but the important point to note here this schedule tasks using cron job works only when app is running if app is closed or terminated this schedule task won't be executed and if you have such requirement to execute tasks even the app is closed then you can go with work manager it execute the background task even the app is closed if you don't know how to schedule tasks using work manager i have already created video on it you can go through that video you can find its link in the description as well as on i button i hope this video was really helpful do consider subscribing my channel and hit the bell button to get further notification on new videos thanks for watching the video [Music] you
Info
Channel: Effortless Code Learning
Views: 5,510
Rating: undefined out of 5
Keywords: flutter, flutter tutorial, effortless code learning, flutter widgets, flutter ui, flutter course, flutter alarm manager, flutter background task, flutter workmanager example, background process, background task in flutter, background task in android, background fetch, flutter workmanager notification, flutter work manager, schedule task flutter, flutter background service notification, flutter cron job, cron job in flutter, cron in flutter, cron job, flutter cron
Id: 3VvmplCs16I
Channel Id: undefined
Length: 6min 55sec (415 seconds)
Published: Tue May 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.