xinthink / flt_worker

Schedule & run Dart code in the background on both Android & iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plugin doesn't work with mainactivity.kt

flutterboi opened this issue · comments

it appears that the plugin does not work when the flutter app uses a kotlin based main activity.
I followed the example and modified the java code to meet the Kotlin syntax but was met with an error saying that it expected a function in java form, not kotlin.

Ditto, any suggestions?

So, I'm try to use this package but now it's to difficult to find the key to register a new package, because they doesn't show in the generatedpluginregistrant file

by the way, probably this it's the kotlin file

package change.this.withyourprojectname

import androidx.annotation.NonNull
import androidx.arch.core.util.Function
import dev.thinkng.flt_worker.FltWorkerPlugin.*
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant


class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        FltWorkerPlugin.registerPluginsForWorkers = Function { registry: PluginRegistry ->
            io.flutter.plugins.pathprovider.PathProviderPlugin.registerWith(
                    registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"))
            //// If you need to add another package
           //// io.flutter.plugins.pathprovider.PathProviderPlugin.registerWith(
           ////         registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"))

            null
        }
    }
}

Has anyone managed to make this work with kotlin?

@hectorAguero have you got a solution?

Can i just register all plugins for the background task?