SyncPolicy class
Network-aware sync policy configuration.
Control when and how location batches are synchronized based on network type, battery state, and app state.
Example:
final config = Config(
syncPolicy: SyncPolicy(
onWifi: SyncBehavior.immediate,
onCellular: SyncBehavior.batch,
onMetered: SyncBehavior.manual,
batchSize: 50,
batchInterval: Duration(minutes: 5),
lowBatteryThreshold: 20,
lowBatteryBehavior: SyncBehavior.manual,
),
);
Constructors
- SyncPolicy({SyncBehavior onWifi = SyncBehavior.immediate, SyncBehavior onCellular = SyncBehavior.batch, SyncBehavior onMetered = SyncBehavior.batch, SyncBehavior onOffline = SyncBehavior.queue, SyncBehavior onCharging = SyncBehavior.immediate, int batchSize = 50, Duration batchInterval = const Duration(minutes: 5), int lowBatteryThreshold = 20, SyncBehavior lowBatteryBehavior = SyncBehavior.manual, Duration minSyncInterval = const Duration(seconds: 30), Duration? maxLocationAge, bool preferWifi = true, bool foregroundOnly = false})
-
Creates a sync policy.
const
- SyncPolicy.fromMap(JsonMap map)
-
Creates from a map.
factory
Properties
- batchInterval → Duration
-
Time interval between automatic batch syncs.
final
- batchSize → int
-
Maximum number of locations per batch.
final
- foregroundOnly → bool
-
Whether to sync only when app is in foreground.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- lowBatteryBehavior → SyncBehavior
-
Sync behavior when battery is below lowBatteryThreshold.
final
- lowBatteryThreshold → int
-
Battery percentage below which to apply lowBatteryBehavior.
final
- maxLocationAge → Duration?
-
Maximum age of a location before it must be synced.
final
- minSyncInterval → Duration
-
Minimum time between sync attempts.
final
- onCellular → SyncBehavior
-
Sync behavior when on cellular data.
final
- onCharging → SyncBehavior
-
Sync behavior when charging.
final
- onMetered → SyncBehavior
-
Sync behavior when on a metered connection.
final
- onOffline → SyncBehavior
-
Sync behavior when device is offline.
final
- onWifi → SyncBehavior
-
Sync behavior when connected to WiFi.
final
- preferWifi → bool
-
Whether to prefer WiFi over cellular even if cellular is faster.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
{SyncBehavior? onWifi, SyncBehavior? onCellular, SyncBehavior? onMetered, SyncBehavior? onOffline, SyncBehavior? onCharging, int? batchSize, Duration? batchInterval, int? lowBatteryThreshold, SyncBehavior? lowBatteryBehavior, Duration? minSyncInterval, Duration? maxLocationAge, bool? preferWifi, bool? foregroundOnly}) → SyncPolicy - Creates a copy with the given fields replaced.
-
getBehavior(
{required NetworkType networkType, required int batteryPercent, required bool isCharging, required bool isMetered, required bool isForeground}) → SyncBehavior - Determines the sync behavior based on current state.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toMap(
) → JsonMap - Converts to a JSON-serializable map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- aggressive → const SyncPolicy
- Aggressive sync - always sync immediately.
- balanced → const SyncPolicy
- Balanced sync - batch on cellular, immediate on WiFi.
- conservative → const SyncPolicy
- Conservative sync - batch everywhere, skip on metered.
- minimal → const SyncPolicy
- Ultra-conservative - only sync on WiFi when charging.