SyncFilter class

Sync filter for selective synchronization

Allows filtering which data gets synced based on conditions, timestamps, and other criteria. This is essential for:

  • Privacy: Users don't want to download everyone's data
  • Bandwidth: Mobile users have limited data plans
  • Storage: Devices have limited space
  • Security: Multi-tenant apps need user isolation
  • Legal: GDPR requires data minimization

Example:

final config = SyncConfig(
  baseUrl: 'https://api.example.com',
  collections: ['todos', 'notes'],
  syncFilters: {
    'todos': SyncFilter(
      where: {'userId': currentUserId},
      since: DateTime.now().subtract(Duration(days: 30)),
    ),
    'notes': SyncFilter(
      where: {
        'userId': currentUserId,
        'archived': false,
      },
    ),
  },
);

Constructors

SyncFilter({Map<String, dynamic>? where, DateTime? since, int? limit, List<String>? fields, List<String>? excludeFields})
const

Properties

excludeFields → List<String>?
Field names to exclude from synced records
final
fields → List<String>?
Field names to include in synced records
final
hashCode → int
The hash code for this object.
no setterinherited
limit → int?
Maximum number of records to sync per pull operation
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
since → DateTime?
Only sync records modified after this timestamp
final
where → Map<String, dynamic>?
Field-based filters for the collection
final

Methods

applyFieldFilter(Map<String, dynamic> data) → Map<String, dynamic>
Apply field filtering to a record
copyWith({Map<String, dynamic>? where, DateTime? since, int? limit, List<String>? fields, List<String>? excludeFields}) → SyncFilter
Create a copy with modified properties
matches(Map<String, dynamic> data, DateTime? updatedAt) → bool
Check if a record matches this filter
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toQueryParams() → Map<String, dynamic>
Convert filter to query parameters for backend requests
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited