How to use the background process task in Flutter

If you want to run some tasks in a period and whatever your app in background or not, you can use the flutter_workmanager plugin!

But before you use it, you need to do some settings on Android and iOS. For Android settings, I think they missed something, I also spent more time and find the solution. After you have done all of the plugin guidelines, if your Android still can’t work, please try below steps:

  1. Upgrade your project to support ‘kotlin’ , this is not a must step, but the plugin is developed by kotlin, if you still want to use java language, you can try this.
  2. Update ‘android/build.gradle‘ file, set the ‘kotlin_version’ to 1.3.0 as below:
buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        google()
        jcenter()
    }
  ...
}

and add the dependencies:

dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.android.gms:play-services-basement:17.0.0'
    }

update the subprojects:

subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }

                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.1"
                }


            }
        }
    }

after that, you should can use the plugin on Android!

But there are some limitations on iOS, it can’t control when will trigger the background task, it just control by iOS, so we just can test and debug this by Xcode, and actually, I tried on my iPhone device, but still can’t see the task to be trigger, so I also want to know whether is working on iOS 🙁

 3,642 total views,  8 views today

Share your vote!


Do you like this post?
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

You may also like...

shares