registerHeadlessSyncBodyBuilder static method

Future<bool> registerHeadlessSyncBodyBuilder(
  1. Future<JsonMap> builder(
    1. SyncBodyContext context
    )
)

Registers a headless-compatible sync body builder.

The callback must be a top-level or static function (not a closure) to work in headless/terminated mode. The callback is invoked by the native side when performing background sync.

Example:

// Must be a top-level function
@pragma('vm:entry-point')
Future<JsonMap> buildSyncBody(SyncBodyContext context) async {
  // Read static config from storage if needed
  final prefs = await SharedPreferences.getInstance();
  final ownerId = prefs.getString('ownerId') ?? '';

  return {
    'ownerId': ownerId,
    'locations': context.locations.map((l) => l.toJson()).toList(),
  };
}

// Register in main()
await Locus.registerHeadlessSyncBodyBuilder(buildSyncBody);

Implementation

static Future<bool> registerHeadlessSyncBodyBuilder(
  Future<JsonMap> Function(SyncBodyContext context) builder,
) {
  return _instance.registerHeadlessSyncBodyBuilder(builder);
}