pull method

  1. @override
Future<List<SyncRecord>> pull({
  1. required String collection,
  2. DateTime? since,
  3. int? limit,
  4. int? offset,
  5. SyncFilter? filter,
})
override

Pull data from backend with optional pagination and filtering

Parameters:

  • collection: Collection name to pull from
  • since: Only pull records modified after this timestamp
  • limit: Maximum number of records to pull
  • offset: Number of records to skip (for pagination)
  • filter: Optional sync filter for selective synchronization

Implementation

@override
Future<List<SyncRecord>> pull({
  required String collection,
  DateTime? since,
  int? limit,
  int? offset,
  SyncFilter? filter,
}) async {
  // Build query parameters
  final queryParams = <String, dynamic>{
    if (since != null) 'since': since.toIso8601String(),
    if (limit != null) 'limit': limit,
    if (offset != null) 'offset': offset,
  };

  // Add filter parameters if provided
  if (filter != null) {
    queryParams.addAll(filter.toQueryParams());
  }

  final response = await _dio.get(
    '/sync/$collection',
    queryParameters: queryParams,
  );

  final records = (response.data['records'] as List?) ?? [];
  return records
      .map((r) => SyncRecord(
            recordId: r['recordId'] as String,
            data: r['data'] as Map<String, dynamic>,
            updatedAt: DateTime.parse(r['updatedAt'] as String),
            version: r['version'] as int? ?? 1,
          ))
      .toList();
}