@@ -191,7 +191,8 @@ class SyncClient {
191191 /// Creates a Sync client associated with the given store and options.
192192 /// This does not initiate any connection attempts yet: call start() to do so.
193193 SyncClient ._(
194- this ._store, List <String > serverUrls, List <SyncCredentials > credentials) {
194+ this ._store, List <String > serverUrls, List <SyncCredentials > credentials,
195+ {Map <String , String >? filterVariables}) {
195196 if (serverUrls.isEmpty) {
196197 throw ArgumentError .value (
197198 serverUrls, "serverUrls" , "Provide at least one server URL" );
@@ -209,6 +210,8 @@ class SyncClient {
209210 C .sync_urls (InternalStoreAccess .ptr (_store), ptr, size),
210211 'failed to create Sync client' ));
211212
213+ filterVariables? .forEach (putFilterVariable);
214+
212215 if (credentials.length == 1 ) {
213216 setCredentials (credentials[0 ]);
214217 } else {
@@ -258,6 +261,40 @@ class SyncClient {
258261 }
259262 }
260263
264+ /// Adds or replaces a [Sync filter] (https://sync.objectbox.io/sync-server/sync-filters)
265+ /// variable value for the given name.
266+ ///
267+ /// Eventually, existing values for the same name are replaced.
268+ ///
269+ /// Sync client filter variables can be used in server-side Sync filters to
270+ /// filter out objects that do not match the filters. Filter variables must be
271+ /// added before login, so before calling `start()` .
272+ ///
273+ /// See also [removeFilterVariable] and [removeAllFilterVariables] .
274+ void putFilterVariable (String name, String value) {
275+ withNativeString (
276+ name,
277+ (nameCStr) => withNativeString (
278+ value,
279+ (valueCStr) => checkObx (
280+ C .sync_filter_variables_put (_ptr, nameCStr, valueCStr))));
281+ }
282+
283+ /// Removes a previously added Sync filter variable value.
284+ ///
285+ /// See also [putFilterVariable] and [removeAllFilterVariables] .
286+ void removeFilterVariable (String name) {
287+ withNativeString (name,
288+ (nameCStr) => checkObx (C .sync_filter_variables_remove (_ptr, nameCStr)));
289+ }
290+
291+ /// Removes all previously added Sync filter variable values.
292+ ///
293+ /// See also [putFilterVariable] and [removeFilterVariable] .
294+ void removeAllFilterVariables () {
295+ checkObx (C .sync_filter_variables_remove_all (_ptr));
296+ }
297+
261298 /// Configure authentication credentials, depending on your server config.
262299 void setCredentials (SyncCredentials creds) {
263300 if (creds is _SyncCredentialsNone ) {
@@ -697,30 +734,43 @@ class Sync {
697734 ///
698735 /// Before [SyncClient.start()] , you can still configure some aspects of the
699736 /// client, e.g. its [SyncRequestUpdatesMode] mode.
737+ ///
738+ /// To configure [Sync filter] (https://sync.objectbox.io/sync-server/sync-filters)
739+ /// variables, pass variable names mapped to their value to [filterVariables] .
740+ ///
741+ /// Sync client filter variables can be used in server-side Sync filters to
742+ /// filter out objects that do not match the filter.
700743 static SyncClient client (
701- Store store, String serverUrl, SyncCredentials credentials) =>
702- clientMultiUrls (store, [serverUrl], credentials);
744+ Store store, String serverUrl, SyncCredentials credentials,
745+ {Map <String , String >? filterVariables}) =>
746+ clientMultiUrls (store, [serverUrl], credentials,
747+ filterVariables: filterVariables);
703748
704749 /// Like [client] , but accepts a list of credentials.
705750 ///
706751 /// When passing multiple credentials, does **not** support
707752 /// [SyncCredentials.none()] .
708753 static SyncClient clientMultiCredentials (
709- Store store, String serverUrl, List <SyncCredentials > credentials) =>
710- clientMultiCredentialsMultiUrls (store, [serverUrl], credentials);
754+ Store store, String serverUrl, List <SyncCredentials > credentials,
755+ {Map <String , String >? filterVariables}) =>
756+ clientMultiCredentialsMultiUrls (store, [serverUrl], credentials,
757+ filterVariables: filterVariables);
711758
712759 /// Like [client] , but accepts a list of URLs to work with multiple servers.
713760 static SyncClient clientMultiUrls (
714- Store store, List <String > serverUrls, SyncCredentials credentials) =>
715- clientMultiCredentialsMultiUrls (store, serverUrls, [credentials]);
761+ Store store, List <String > serverUrls, SyncCredentials credentials,
762+ {Map <String , String >? filterVariables}) =>
763+ clientMultiCredentialsMultiUrls (store, serverUrls, [credentials],
764+ filterVariables: filterVariables);
716765
717766 /// Like [client] , but accepts a list of credentials and a list of URLs to
718767 /// work with multiple servers.
719768 ///
720769 /// When passing multiple credentials, does **not** support
721770 /// [SyncCredentials.none()] .
722771 static SyncClient clientMultiCredentialsMultiUrls (
723- Store store, List <String > serverUrls, List <SyncCredentials > credentials) {
772+ Store store, List <String > serverUrls, List <SyncCredentials > credentials,
773+ {Map <String , String >? filterVariables}) {
724774 if (syncClientsStorage.containsKey (store)) {
725775 throw StateError ('Only one sync client can be active for a store' );
726776 }
0 commit comments