Flutter has no built-in background service. Use a plugin such as flutter_background_service (Android foreground service) or workmanager (scheduled tasks), and expect strict limits on iOS.
A background task runs your Dart code in a separate isolate, with no access to your widgets or in-memory app state. What the operating system allows differs a lot between platforms.
- Android: a foreground service with a visible notification can run long tasks; scheduled work through WorkManager survives restarts but is deferred and batched by the system.
- iOS: there is no long-running service. Background fetch and processing tasks are scheduled by the system, may run rarely, and can be stopped at any time. Audio, location and VoIP have their own background modes.
- Use push notifications when the server knows something happened; they are more reliable than polling.
// pubspec.yaml: flutter_background_service
@pragma('vm:entry-point')
void onStart(ServiceInstance service) {
Timer.periodic(const Duration(minutes: 1), (_) {
// do work, then optionally update the notification
});
}
Future<void> initService() async {
await FlutterBackgroundService().configure(
androidConfiguration: AndroidConfiguration(
onStart: onStart,
isForegroundMode: true,
autoStart: false,
),
iosConfiguration: IosConfiguration(onForeground: onStart),
);
await FlutterBackgroundService().startService();
}Package APIs change between releases, so check the plugin's documentation for the current options, and declare the foreground-service permission and type in AndroidManifest.xml.
Background work is hard to observe in the field. Bugsee records errors and logs from your Flutter app, so issues that only happen off-screen leave a trail. Learn more
