How to create a Flutter background service that works also when app closed

For this kind of things you have to rely on native mechanisms.

The most efficient way to deal with APIs in an "always existent" background component is to implement a push notification service. Using that kind of tech a remote server is capable of starting communication with your app, awaken it and then perform whatever task needs to be performed.

Also, in Android, you have foreground services which will run even if the app is closed.


Can I run Dart code in the background of an Flutter app?

Yes, you can run Dart code in a background process on both iOS and Android. For more information, see the Medium article Executing Dart in the Background with Flutter Plugins and Geofencing.

Credit to Raouf Rahiche


You might want to have a look at flutter_background_service package. It helps executing Dart code in the background.