Package selection guidance compiled from public package information, community data, and project usage.
Flutter Background Executor is a plugin designed to handle background tasks on Android and iOS. It enables both scheduled refresh tasks and immediate execution of background operations, ensuring reliable task processing even when the app is inactive. Ideal for syncing data, updating caches, or running periodic maintenance, it provides a lightweight solution for background execution without requiring complex native code. The plugin integrates seamlessly with Flutter apps and supports platform-specific configurations through its source code on GitHub.
Use cases
Scheduled data sync
Background cache updates
Periodic maintenance tasks
Push notification handling
Real-time status polling
Key features
Supports scheduled and immediate background tasks
Cross-platform (Android & iOS)
Lightweight and easy to integrate
Open-source with public repository
Minimal configuration required
Suitable for
Apps needing regular background updates
Offline-first applications
Data-intensive mobile apps
Apps with real-time requirements
Developers seeking simple background execution
Considerations
Requires proper platform permissions
Battery usage should be monitored
Limited to specific OS background execution policies
May require foreground service setup on Android
Not suitable for long-running intensive tasks
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
To run background tasks, this library creates
new Flutter Engine
. This allows you to run tasks when the application is in the background. In fact, the background
task and the main application are different applications that cannot communicate using basic Flutter
tools. But this is possible if you use the native part of the application and this
is implemented in this library.
Warning: Some libraries may not be ready for this use. But in most cases, you can find a workaround with task management.
Scheduled refresh task
Flutter
To schedule a refresh task, call the createRefreshTask function.
Warning: If you are using Flutter 3.3.0 or newer, you must annotate the refresh task function with @pragma('vm:entry-point').
Note: You can schedule only one refresh task.
Android
To set up a scheduled refresh task on Android, you can change the following options:
Option
Type
Description
Default value
requiredNetworkType
AndroidNetworkType
The type of network required for the work to run.
AndroidNetworkType.notRequired
requiresCharging
bool
Whether device should be charging for the work to run.
false
requiresDeviceIdle
bool
Whether device should be idle for the work to run(Android SDK 23+).
false
requiresBatteryNotLow
bool
Whether the device's battery level must be acceptable for the work to run.
false
requiresStorageNotLow
bool
Whether the device's available storage should be at an acceptable level for the work to run.
false
minUpdateDelay
Duration
Sets the delay that is allowed from the time a content.
Duration(minutes: 15)
maxUpdateDelay
Duration
Sets the maximum delay that is allowed from the first time a content.
Duration(hours: 1)
initialDelay
Duration
Sets an initial delay for the work.
Duration(minutes: 3)
repeatInterval
Duration
The repeat interval.
Duration(minutes: 15)
flexInterval
Duration
The duration for which this work repeats from the end of the repeatInterval.
Duration(minutes: 15)
iOS
To set up a background task on iOS, you need to do the following:
Need to add capability Background Modes
Need to select Background fetch and Background processing
Need to set background task identifier in Info.plist
on Permitted background task scheduler identifiers(BGTaskSchedulerPermittedIdentifiers)
The required steps for configuring background work are now complete. But in this case, the task will
be configured only on the second run. This is due to the fact that iOS allows you to configure
background tasks only during the launch of the application itself. In order to set up a task for the
first run, you need to pass the task identifier to the plugin:
For iOS, you can not set the frequency of the background task. The system itself determines the
launch time depending on how the user uses the application and the phone as a whole. To check the
setting, you can use the command:
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"taskID"]
Immediate task
To run a immediately task, call the runImmediatelyBackgroundTask function.
Note: You can run many immediate tasks, but you need to use different task identifier for different tasks.
Communication between tasks
You can send messages from the application to a background task, from a background task to the
application, and from one background task to another background task. Also, if you need, you can
send a common message that will be send to all tasks except the current one.
Communication between tasks works with EngineConnector object. You can use it for receive message
and send message. For now, you can send only string message, but you can use encode to json and
decode from json for sending objects.
To get an EngineConnector object you can use createConnector method. To work correctly, you must
use the identifier of the current task.
Note: You cannot communicate with the scheduled refresh task.
Warning: For now, you can use communication only for immediate tasks.
Task management
You can check if a specific task or any tasks are currently running, and you can also stop them.
This is useful for working around the problems with libraries that don`t support in any tasks.
Note: You can manage tasks from any task. Be careful.
Note: You can always cancel a scheduled refresh task.
Warning: If you set the cancellable parameter to false when creating an immediate task, you can`t to stop it.
Cancelling scheduled refresh task
Also you can cancel the scheduled refresh task and it will not work in future.
To stop a scheduled refresh task, you need to use the identifier returned when the task was created.
For now, you can also use the following method to cancel a scheduled refresh task, but it cancels
all scheduled refresh tasks. As long as the plugin only supports one refresh task, it's the same
solution.