> For the complete documentation index, see [llms.txt](https://docs.nubrick.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nubrick.app/reference/flutter/nubrickuser.md). Agents can also search and read this documentation through its [MCP server](https://docs.nubrick.app/~gitbook/mcp).

# NubrickUser

### インターフェース <a href="#interface" id="interface"></a>

```dart
class NubrickUser {
  Future<String?> getId()
  Future<void> setProperties(Map<String, dynamic> properties)
  Future<Map<String, String>?> getProperties()
}
```

### .getId <a href="#id" id="id"></a>

NubrickUser にはデフォルトでUUID形式のユーザーIDがプロパティとして設定されています。ユーザーIDは以下のように取得できます：

```dart
final user = NubrickUser();
final userId = await user.getId();
```

オプションで、カスタムユーザーIDを設定することも可能です：

```dart
await user.setProperties({'userId': '<CUSTOM_USER_ID>'});
```

{% hint style="warning" %}
この値は、施策のデータを収集するためにNubrickサーバーに送信されます。そのため、ユーザーIDとしてプライバシーに関わるデータを設定することは推奨されません。
{% endhint %}

### .setProperties <a href="#set" id="set"></a>

{% hint style="info" %}
このプロパティは、

* どのユーザーが施策のターゲットとなるかをフィルタリングする
* 施策内のユーザー毎の動的な変数として表示する

ために使用されます。
{% endhint %}

{% hint style="warning" %}
SDK v0.3.2未満では、カスタムのユーザープロパティはIn-memoryに保存される仕様となっています。アプリ起動時に、都度ユーザーのプロパティをsetしていただく実装が必要です。

SDK v0.3.2では、アプリ内のストレージに保存するよう修正しましたので、一度設定したユーザープロパティは、アプリの再起動後も永続化されます。
{% endhint %}

カスタムのユーザーのプロパティを設定することができます：

```dart
await user.setProperties({'<KEY>': '<VALUE>'});
```

また、 `<VALUE>` は `String`, `bool`, `int`, `double`, `DateTime` をサポートしています。 (SDK >= v0.9.0)

キーに使える文字は半角英数字と `_` `-` のみです。camelCase（`isPremium` など）を推奨します。詳細は [ユーザー属性情報（setProperties）について](https://docs.nubrick.app/other/setproperties.md) を参照してください。

### .getProperties <a href="#comeback" id="comeback"></a>

ユーザーのプロパティを取得することができます：

```dart
final properties = await user.getProperties();
```
