flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

Got error "onStart method must be a top-level or static function" when I changed the function call.

Open swayamshreemohanty opened this issue 2 years ago • 2 comments

When I'm passing the method like this, then it is working fine:

await flutterBackgroundService.configure(
    androidConfiguration: AndroidConfiguration(
      // this will be executed when app is in foreground or background in separated isolate
      onStart: onStart,

      // auto start service
      autoStart: true,
      isForegroundMode: false,

But If I want to call the onStart() method there, it is showing error of: Unhandled Exception: onStart method must be a top-level or static function. I want to pass some other data to the onStart() to run my custom task in the background. How to do it?

    await flutterBackgroundService.configure(
      androidConfiguration: AndroidConfiguration(
        // this will be executed when app is in foreground or background in separated isolate
        onStart: (service) {
          onStart(service);
        },

        // auto start service
        autoStart: true,

swayamshreemohanty avatar Nov 05 '22 13:11 swayamshreemohanty

Same issue here. I can't figure out what the go to solution for communication between the background service and my app is supposed to be.

mattifrind avatar Dec 12 '22 16:12 mattifrind

Has anyone been able to pass parameters to the onStart method?

msouzarunner avatar Jun 06 '23 13:06 msouzarunner