Flutter - Create and Schedule Background Tasks in Flutter | Flutter Workmanager [2022]

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

Комментарии • 89

  • @EffortlessCodeLearning
    @EffortlessCodeLearning  2 года назад +3

    Below link for this video tutorial source code,
    github.com/ritsat/workmanager_example
    Thank you for watching the video 😀

  • @kerandonovan7255
    @kerandonovan7255 Год назад +3

    Thank you i enjoyed your clear and logical style. The music when you are typing also had me🤣

  • @harshitrv8503
    @harshitrv8503 7 месяцев назад

    Worked like a charm. Thanks a lot!

  • @someshsahu4638
    @someshsahu4638 Год назад +1

    nice video thank you so much 🙏🏼🙏🏼🙏🏼

  • @muizahsanu4521
    @muizahsanu4521 2 года назад +4

    hey thanks for the tutorial. can "frequency: Duration()" set by days?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +4

      Thanks for watching the video. Yes you set duration in days using days property of Duration class.
      Refer below link for more details,
      api.flutter.dev/flutter/dart-core/Duration/inDays.html

  • @tahaaiyaaz7962
    @tahaaiyaaz7962 Год назад +1

    thnaks a lot bro but i have a doubt will it work even if we close the app?

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      It works in closed app state ? Or what service did u use ?

  • @vlog.tourprasenjit
    @vlog.tourprasenjit Год назад +3

    The background task working fine in emulator but physical device not working properly. How can I resolve this?

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      It seems that it doesn't work on Android 8 or new verstions of Android

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Did You find a solution?

  • @malluvocalist1416
    @malluvocalist1416 7 месяцев назад

    how to customize this. by default in the notification it is showing like result dart etc and some emogi's can i remove that is it possible. can you suggest another good package for putting reminder for events

  • @judejude5134
    @judejude5134 2 года назад +2

    Hi sir , thanks for the tutorial.

  • @crazy-man
    @crazy-man 2 года назад +2

    how can I run the task after rebooting the device? for example, to set notifications again, since they are reset after a reboot, they say this can be done using this workmanager package

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +2

      Refer below links for this, there ways provided by other developers,
      github.com/googlecodelabs/android-workmanager/issues/157
      github.com/fluttercommunity/flutter_workmanager/issues/180

  • @LMrc534
    @LMrc534 2 года назад +1

    thank you. ECL
    Plse can you make a tuto How to run some task like stopwatch in background .

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +1

      Thank you Leo for watching the video.
      If you want to implement stopwatch, you can use Timer & Stopwatch classes in flutter.
      api.flutter.dev/flutter/dart-core/Stopwatch-class.html
      api.flutter.dev/flutter/dart-async/Timer-class.html
      It can be implemented using package too. Below package can help you.
      pub.dev/packages/stop_watch_timer
      If you want video on stop watch Or if you have any other query/suggestion, please let me know.

    • @LMrc534
      @LMrc534 2 года назад

      I already implement a stopwatch but it can't keep running in background.

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      did you implement it using workmanager or any other way? Just want to understand.

    • @LMrc534
      @LMrc534 2 года назад

      @@EffortlessCodeLearning please make a video about stopwatch an work manager,,🙏🙏🙏🙏🙏🙏🙏

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Sure, I will make it soon.

  • @rjrmatias
    @rjrmatias Год назад

    excellent tutorial, thank you !

  • @adnanhaider9949
    @adnanhaider9949 4 месяца назад

    is it possible to throw a APi call post or get when app in terminate state using this method?

  • @Kyash108
    @Kyash108 2 года назад +4

    The periodic task doesn’t work on iOS. Do you know an alternative for that?

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      What did You use ? Cron ? Or flutter_background_service ?

    • @Kyash108
      @Kyash108 10 месяцев назад

      Sorry no idea which project I was working on. Don’t remember what I ended up using.

  • @abdrhmankafo8301
    @abdrhmankafo8301 2 года назад

    Thanks for this video Can I call this function every 5 sec when app in the background works

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Thanks for watching the video.
      Sorry the minimum duration you can set using workmanager is 15 mins. Android doesn't allow duration less than 15 mins for workmanager.
      May be you will need to check other approach for this requirement.

    • @abdrhmankafo8301
      @abdrhmankafo8301 2 года назад

      @@EffortlessCodeLearning can u recommend me another approtoin

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +1

      @@abdrhmankafo8301 Sure, I will check & let you know soon.

    • @abdrhmankafo8301
      @abdrhmankafo8301 2 года назад

      @@EffortlessCodeLearning thanks man

  • @imaddeveloper5760
    @imaddeveloper5760 Год назад

    Great tutorial, thank you

  • @thevoicep6562
    @thevoicep6562 10 месяцев назад

    Dude I have a question It works when the app is closed ?

  • @achmadsyarif5129
    @achmadsyarif5129 2 года назад +2

    Hi sir nice tutorial, I wanna ask something, I want to make background local notifications using work manager and provider state management, but I cannot access the context for provider because it is outside of the widget, how can I get the context?thanks in advance

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Thank you Achmad for watching the video. Can you please share your code, so I can provide the exact solution.

    • @reemaahuja8397
      @reemaahuja8397 2 года назад +1

      yes same issue .. Is it necessary to call callback dispatcher in main.dart file ?
      Or is there any other way to access context in call back dispatcher.

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Hey bro, did You find a solution ? Can You show me how to do it ? 🙏

  • @stackflow4007
    @stackflow4007 Год назад

    Thanks! great video and explanation! 👌👌👌👌👏👏👏👏👏👏👍🏼👍🏼
    What are the scenarios, its good to use a cronjob over Work manager?

  • @kunalb2051
    @kunalb2051 11 месяцев назад +1

    what if you want to run background task every minute, any suggestions?

    • @telugumanga184
      @telugumanga184 9 месяцев назад

      Did you get any solution bro

    • @kunalb2051
      @kunalb2051 9 месяцев назад

      ​@@telugumanga184 yes you can use workmanager package for periodic task, minimun timpeperiod is 60secs

  • @d-apps2699
    @d-apps2699 Год назад

    I didn't udnerstand, how do I execute a function in background periodic?

  • @narolabrothersdeveloper
    @narolabrothersdeveloper 11 месяцев назад

    can i schedule zoned notification and get notification when app was close????

  • @SaitamaMixed
    @SaitamaMixed 6 месяцев назад

    so this work even if the app got closed?

  • @Krishna-vp8mf
    @Krishna-vp8mf 2 года назад +1

    How can we run querry in background, I want query.length for my notification content to show messages count in notification.

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +1

      Thank you Piyush for watching the video. If you elaborate the scenario further or provide any related code snippet, it will help me to provide the solution.

    • @Krishna-vp8mf
      @Krishna-vp8mf 2 года назад

      ​@@EffortlessCodeLearningThanks for reply,
      Main.dart have this code
      void callbackDispatcher() {
      Workmanager().executeTask((taskName, inputData) async {
      //show the notification
      await Firebase.initializeApp();
      totalcalls() async {
      var callsRecord = queryCallsRecord(
      queryBuilder: (callsRecord) => callsRecord
      .where('attended', isEqualTo: 'false'));
      var _equals = await callsRecord.length;
      return
      createcallNotification(title: "Calls Pending", count:callsRecord.length );}

      return
      Future.value(true);
      });
      }
      and above task excuted from homepage code
      Workmanager().registerPeriodicTask("BackgroundNotificationStart",
      "BackgroundNotification",frequency: Duration(minutes: 15)
      but this isnt working dont know why

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      @Piyush, what is the exact issue you are facing with this code? Did you try to print any sample message in Workmanager().executeTask method to check if it is getting triggered?

  • @mohamedrjeb610
    @mohamedrjeb610 2 года назад

    Will this work if the app is closed or losing focus ?
    will it work after rebooting the phone ?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Yes. it will work if app is closed or lost the focus.
      To work after reboot, need some other workaround. Refer below link, there are ways provided by other developers,
      github.com/googlecodelabs/android-workmanager/issues/157
      github.com/fluttercommunity/flutter_workmanager/issues/180

  • @csabaszy7715
    @csabaszy7715 2 года назад

    Hi, I would like to use workmanager, with webview_pro. Can I just keep alive my webview in the background with workmanager?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Not sure about this but webview is a widget & widget may not be keep alive in the background.

  • @alvaradomeradanieledinson4476
    @alvaradomeradanieledinson4476 Год назад

    me funciona bien en segundo plano pero se ejecuta muchas veces no entiendo porque incluso esta la frecuencia 15 minutos

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Cómo solucionaste ? Estoy empezando en esto y Vi que hay una alternativa llamada flutter_backgroundserivce

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Para que necesitabas tareas en segundo plano?

  • @ivillage5872
    @ivillage5872 Год назад +3

    One thing you are not saying!!! This doesn't work when the app is killed

    • @minhduc8a21
      @minhduc8a21 11 месяцев назад +1

      😢

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Bro, what service can I use for app work in killed state ? 🥺

    • @omarmaamoun9457
      @omarmaamoun9457 10 месяцев назад +1

      F

    • @anonymousghost5384
      @anonymousghost5384 6 месяцев назад

      ​@@thevoicep6562 there is a situation that you app ui got killed but service is running in background and confuses to intract with ui

  • @MOFYILD
    @MOFYILD 2 года назад +1

    Is this useful for pedometer?

  • @jonkc3635
    @jonkc3635 2 года назад

    When I close the Android app on my emulator, I got the message "Lost connection to device." in the terminal which means the app will not be running in the background anymore. Any thoughts on this?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      This message is because the socket connection between your editor(Android studio/ VS code) & app on emulator is terminated. App should be working in the background. Best way to verify it on really device. You can deploy your app on mobile & check.

    • @jonkc3635
      @jonkc3635 2 года назад

      @@EffortlessCodeLearning Thank you for the reply. I have also tried running this app on my android device and it also fully closes the app. I get the same message "Lost connection to device" when closing the app. I ended up using the package flutter_background_service which works great so far.

    • @gitarthakashyap8519
      @gitarthakashyap8519 Год назад

      @@jonkc3635 build the app and then run

    • @thevoicep6562
      @thevoicep6562 10 месяцев назад

      Bro, can You share your code ? I woukd like to know how to use flutter_background_service​@@jonkc3635

  • @ahmedabdaa3468
    @ahmedabdaa3468 2 года назад

    I want to show a dialog when alarm is run at specific time even app is closed
    Is this possible?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      You can show dialog only when app is open. It is not possible for closed app. But instead of dialog you may show notification.

    • @ahmedabdaa3468
      @ahmedabdaa3468 2 года назад

      @@EffortlessCodeLearning 1 year ago i did it with android native so i think it is possible but need some search

  • @Tech1st
    @Tech1st 2 года назад +1

    only for android?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +1

      No, work manger package support iOS too. But as I have Windows machine only, so I can only cover Android part. Sorry for it.

    • @Tech1st
      @Tech1st 2 года назад

      @@EffortlessCodeLearning so ios support periodically task?

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      Yes, as per the documentation, periodic task is supported in ios. Refer below package page for more details,
      pub.dev/packages/workmanager

  • @Hazrat18903
    @Hazrat18903 Год назад

    Hello Sir!
    Sir my super visor give me the idea for final year project to create a flutter app which will open by volume button or on double tap on screen and then automatically start your device voice recorder and record voice for specific time and also take some picture automatically and then send this all data on WhatsApp number
    so please help me sir

  • @FlutteringWithAnas
    @FlutteringWithAnas Год назад

    I Loved Your Videos. And Love The Way You Explain The Things. And I Would Request You To Please Make A Video On in-App-Purchase Package Of Flutter. Don't Use Any Other Package Than Flutter's Official in-App-Purchase. It Will Be Really A Great Aid To Me And Many Others As Well. I Haven't Seen Any Well Informing Video On This Topic. This Will Surely Boost Your Views Too. Thanks Mate. Like And Subscribe For You.

  • @mohsinirfan4498
    @mohsinirfan4498 2 года назад +1

    not working properly when app is closed

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      I will check this & let you know.

    • @GowthamkumarM-zx3no
      @GowthamkumarM-zx3no Год назад +1

      @@EffortlessCodeLearning did you check for this issue. I'm also facing the same issue... Is there any other solution if i want to run certain function even app is closed?

  • @paranthamanarumugam4172
    @paranthamanarumugam4172 2 года назад +1

    Hi Thanks for the video I have question here you initialize workmanager in main() The print statement taskname why not continually print logcat ..? background continually print what can I do
    Periodic task we can run 15min once only we get the output..but I need 5 seconds once if it's possible ..? Or send me message to my mail id

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад +1

      @Paranthaman Arumugam: Thanks for watching the video.
      Workmanager support minimum task schedule time is 15 min. Even though if you set less than 15 min, it sets it back to 15 min.
      If you want scheduling time less 15 min then you need to use any alternate approach like,
      You can use Timer.periodic(Duration(seconds: 5), {}) method, but the timer work only when app is running, it will be stopped as soon as app is closed. So you will have to write the background service/code explicitly in android/iOS.

    • @paranthamanarumugam4172
      @paranthamanarumugam4172 2 года назад +1

      @@EffortlessCodeLearning @Effortless Code Learning Thanks for your reply that's you come up with correct point. And I done Timer.periodic that's fine working me Thanks once again.

    • @EffortlessCodeLearning
      @EffortlessCodeLearning  2 года назад

      @@paranthamanarumugam4172 Glad to hear that.