Flutter Workmanager Task not updating with app update

283

Through testing and debugging using adb to update the app (flutter run is not suitable), the resolution was to add existingWorkPolicy: ExistingWorkPolicy.append to the periodic task registry.

Share:
283
BadgerHobbs
Author by

BadgerHobbs

Updated on December 01, 2022

Comments

  • BadgerHobbs
    BadgerHobbs over 1 year

    So I have an issue where my existing Flutter Workmanager background task is not updating automatically following the app's update.

    I have the example code which sets up a periodic Workmanager job.

    void main() async
    {
      WidgetsFlutterBinding.ensureInitialized();
      
      Workmanager().initialize(
          callbackDispatcher
        );
    
      await Workmanager().registerPeriodicTask(
          "ExampleTask",
          "ExampleTaskPeriodicTask",
          initialDelay: Duration(minutes: 15,
          frequency: Duration(hours: 1)
        );
    }
    
    void callbackDispatcher() async
    {
      Workmanager().executeTask((task, inputData) async 
      {
        await DoSomething();
        
        return Future.value(true);
      }); 
    }
    
    

    If I update DoSomething() in my background task, currently it does not update for the user and it would continue doing the old thing, not the new thing.

    Is there any way to update the background task without the user having to do anything following the apps automatic update?