setUserProperty method

Future<void> setUserProperty({
  1. required String name,
  2. required String? value,
  3. AnalyticsCallOptions? callOptions,
})

Sets a user property to a given value.

Up to 25 user property names are supported. Once set, user property values persist throughout the app lifecycle and across sessions.

name is the name of the user property to set. Should contain 1 to 24 alphanumeric characters or underscores and must start with an alphabetic character. The "firebase_" prefix is reserved and should not be used for user property names.

Setting a null value removes the user property.

Implementation

Future<void> setUserProperty({
  required String name,
  required String? value,
  AnalyticsCallOptions? callOptions,
}) async {
  if (name.isEmpty ||
      name.length > 24 ||
      name.indexOf(_alpha) != 0 ||
      name.contains(_nonAlphaNumeric)) {
    throw ArgumentError.value(
      name,
      'name',
      'must contain 1 to 24 alphanumeric characters.',
    );
  }

  if (name.startsWith('firebase_')) {
    throw ArgumentError.value(name, 'name', '"firebase_" prefix is reserved');
  }

  await _delegate.setUserProperty(
    name: name,
    value: value,
    callOptions: callOptions,
  );
}