updateProperties method

Future<bool> updateProperties(
  1. Map<String, dynamic> properties
)

Updates multiple subscription properties simultaneously.

Properties are key-value pairs that can be used to segment users or customize notification content. This method allows batch updates to properties.

Parameters:

  • properties: Map of property names to their values
    • Set a value to null to remove the property

Example:

await SuperFCM.instance.updateProperties({
  'userType': 'premium',
  'lastLogin': DateTime.now().toIso8601String(),
  'oldProperty': null, // This will remove the property
});

Implementation

Future<bool> updateProperties(Map<String, dynamic> properties) async {
  return _queueOrExecute("updateProperties", () async {
    logger.d('Updating ${properties.length} properties');
    final response = await _patch(
        'subscriptions/${subscription?.id}',
        {
          'properties': properties,
        },
        _config!.cacheOnOffline);

    return _handleResponse(
      response,
      'update properties',
      onSuccess: (response) {
        if (subscription != null) {
          final Map<String, dynamic> updatedProps = Map<String, dynamic>.from(
            subscription!.properties ?? {},
          );

          // Update or remove properties based on the provided values
          properties.forEach((key, value) {
            if (value == null) {
              updatedProps.remove(key);
            } else {
              updatedProps[key] = value;
            }
          });

          subscription = subscription!.copyWith(properties: updatedProps);
          _storeSubscription();
        }
      },
    );
  });
}