---
schema_version: "1"
id: 2200ee1e1f088467bf87c886b62cf1cb1eb2961b7ebfecd7f6850cb9ba8a72f5
title: setAttribute
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud-mobilepush/engagement_sdk/references/flutter/flutter_setAttribute.md
canonical_url: https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/flutter_setAttribute.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4d907fbb4e9e37e985be24bf093e319d4878d7c500d5283454efe12ea832faaa
products:
  - Salesforce Engagement SDK
---
# setAttribute

Sets a custom attribute for the device.

## Syntax

```dart
Future<void> setAttribute(String key, Object? value)
```

## Parameters

- `key` (String) - The attribute key
- `value` (Object?) - The attribute value

## Returns

- `Future<void>` - Completes when the attribute has been set.

## Example

```dart
try {
  await SfmcSdk.setAttribute('userType', 'premium');
  await SfmcSdk.setAttribute('lastLogin', DateTime.now().toIso8601String());
  print('Attributes set successfully');
} catch (e) {
  print('Failed to set attribute: $e');
}
```

## Related Methods

- [getAttributes()](https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/flutter_getAttributes.md)
- [clearAttribute()](https://developer.salesforce.com/docs/marketing/mobile-unified-sdk/references/engagement-mobile-sdk-reference/flutter_clearAttribute.md)
