> 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/nubrickdispatcher.md).

# NubrickDispatcher

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

```dart
class NubrickDispatcher {
  Future<void> dispatch(NubrickEvent event)
}
```

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

dispatch関数は、アプリ内のさまざまなイベントを定義するために使用できます。これにより、**イベントデータがNubrickサーバーに送信**され、Nubrickプラットフォームにおいて様々な用途で活用することができます。

この関数を使用することで、特定のエクスペリメントを表示させるトリガーを設定できたり、アプリ内でのユーザーのアクションやイベントをトラッキングし、アプリのパフォーマンスやユーザーの行動分析を行うことが可能になります。

{% hint style="success" %}
具体的なユースケース

* アプリ内でモーダルを表示させるトリガーとして使用。例えば、特定のボタンがクリックされた際や、特定のページを閲覧した際にモーダルを表示するなど。
* アプリ内でのKPIを評価するために使用。特定の機能がユーザーによってどれくらい利用されているかや、特定のUIをどれだけタップしているかを計測するなど。
  {% endhint %}

#### イベントを送信する際のコード例

```dart
import 'package:nubrick_flutter/dispatcher.dart';

await NubrickDispatcher().dispatch(NubrickEvent("<CUSTOM_EVENT_NAME>"))
```

### 詳細な使用例 <a href="#examples" id="examples"></a>

#### アプリのXX機能を利用しているユーザーをトラッキング

```dart
import 'package:nubrick_flutter/dispatcher.dart';

Button(
  child: const Text('Press me!')
  onPressed: () {
    NubrickDispatcher().dispatch(NubrickEvent('PRESS_XX_FEATURE'))
  }
)
```

#### アプリ内でYYページを表示したときにXXイベントをトリガーまたは収集

```dart
import 'package:nubrick_flutter/dispatcher.dart';

class NubrickNavigatorObserver extends NavigatorObserver {
  @override
  void didPush(Route<dynamic> route, Route<dynamic>? result) {
    super.didPop(route, result);
    String name = route.settings.name ?? '';
    if (name.isNotEmpty) {
      NubrickDispatcher().dispatch(NubrickEvent('NAVIGATION_$name'));
    }
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? result) {
    super.didPop(route, result);
    String name = route.settings.name ?? '';
    if (name.isNotEmpty) {
      NubrickDispatcher().dispatch(NubrickEvent('NAVIGATION_$name'));
    }
  }
}

// ...
MaterialApp(
  routes: {
    // ...
  },
  navigatorObservers: [
    NubrickNavigatorObserver(),
  ],
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.nubrick.app/reference/flutter/nubrickdispatcher.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
