TaskOptions class

Configuration options for scheduling background tasks.

This class encapsulates all the parameters needed to schedule a background task, including timing, constraints, and retry behavior. It provides validation to ensure the options are compatible with Android's WorkManager and AlarmManager.

Constructors

TaskOptions({required String id, bool periodic = false, Duration? frequency, Duration initialDelay = Duration.zero, bool requiresCharging = false, bool requiresWifi = false, bool retryOnFail = true, int maxRetryAttempts = 5, Map<String, dynamic>? data})
Creates a new TaskOptions instance.
const
TaskOptions.fromJson(String source)
Creates a TaskOptions from JSON string.
factory
TaskOptions.fromMap(Map<String, dynamic> map)
Creates a TaskOptions from a Map (deserialization).
factory

Properties

data Map<String, dynamic>?
Additional data to pass to the task callback.
final
frequency Duration?
Frequency for periodic tasks.
final
hashCode int
The hash code for this object.
no setteroverride
id String
Unique identifier for the task.
final
initialDelay Duration
Initial delay before the first execution.
final
maxRetryAttempts int
Maximum number of retry attempts when retryOnFail is true.
final
periodic bool
Whether this is a periodic (repeating) task or one-time task.
final
requiresCharging bool
Whether the task requires the device to be charging.
final
requiresWifi bool
Whether the task requires a WiFi connection.
final
retryOnFail bool
Whether the task should retry on failure with exponential backoff.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

copyWith({String? id, bool? periodic, Duration? frequency, Duration? initialDelay, bool? requiresCharging, bool? requiresWifi, bool? retryOnFail, int? maxRetryAttempts, Map<String, dynamic>? data}) TaskOptions
Creates a copy of this TaskOptions with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() String
Converts this TaskOptions to JSON string.
toMap() Map<String, dynamic>
Converts this TaskOptions to a Map for serialization.
toString() String
A string representation of this object.
override
validate() → void
Validates the task options and throws appropriate exceptions if invalid.

Operators

operator ==(Object other) bool
The equality operator.
override