# Variation Distribution

When running an A/B Test, you need to assign users to Variations and implement logic for each Variation. You can use the Hackle SDK to handle this user distribution.

## variation

Pass the **Experiment Key** to the `variation()` method to assign users to a Variation and receive the result.

<table><thead><tr><th width="150">Parameter</th><th width="120">Type</th><th width="110">Required</th><th>Constraints</th></tr></thead><tbody><tr><td>Experiment Key (key)</td><td><code>int</code></td><td>Required</td><td>-</td></tr></tbody></table>

#### Example

In the example code below, Experiment Key 42 is passed, and there are two Variations: A and B.

```dart
import "package:hackle/hackle.dart";

// Determines which Variation to show to the user in the A/B Test with Experiment Key 42.
// Returns Variation A if a decision cannot be made.
Variation variation = await HackleApp.variation(42);

// Logic for the assigned Variation
if (variation == Variation.A) {
  // Group A logic
} else {
  // Group B logic
}
```

## variationDetail

The `variationDetail()` method works the same as `variation()` but additionally provides the reason for the distribution decision. This method is useful for verifying that distribution is working correctly.

<table><thead><tr><th width="150">Parameter</th><th width="120">Type</th><th width="110">Required</th><th>Constraints</th></tr></thead><tbody><tr><td>Experiment Key (key)</td><td><code>int</code></td><td>Required</td><td>-</td></tr></tbody></table>

#### Example

You must pass the Experiment Key as a parameter. In the example below, Experiment Key 42 is passed.

```dart
import "package:hackle/hackle.dart";

// Variation distribution decision detail
Decision decision = await HackleApp.variationDetail(42);

// Assigned Variation
Variation variation = decision.variation;

// Decision reason
DecisionReason reason = decision.reason;
```

### Decision Reason

The decision reason is returned in a format such as **`SDK_NOT_READY`**. Refer to the table below for details.

<table><thead><tr><th width="319.12109375">Distribution Reason</th><th width="305.35546875">Description</th><th>Distribution Result</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td><p>The SDK is not ready to use.</p><p>(e.g., initialization attempted with an invalid SDK Key)</p></td><td>A (Control Group)</td></tr><tr><td><code>EXPERIMENT_NOT_FOUND</code></td><td>No A/B Test was found for the provided Experiment Key. The Experiment Key may be incorrect, or the experiment may be archived.</td><td>A (Control Group)</td></tr><tr><td><code>NOT_IN_MUTUAL_EXCLUSION_EXPERIMENT</code></td><td>The experiment is included in Mutually Exclusive Settings, but<br>the user was not assigned to that Mutually Exclusive Group.</td><td>A (Control Group)</td></tr><tr><td><code>EXPERIMENT_DRAFT</code></td><td>The A/B Test is in draft state.</td><td>A (Control Group)</td></tr><tr><td><code>EXPERIMENT_PAUSED</code></td><td>The A/B Test is paused.</td><td>A (Control Group)</td></tr><tr><td><code>EXPERIMENT_COMPLETED</code></td><td>The A/B Test has ended.</td><td>Winning Variation selected at completion</td></tr><tr><td><code>OVERRIDDEN</code></td><td>The user was assigned to a specific group<br>by Override.</td><td>Override-assigned<br>group</td></tr><tr><td><code>NOT_IN_EXPERIMENT_TARGET</code></td><td>The user is not an A/B Test target.</td><td>A (Control Group)</td></tr><tr><td><code>TRAFFIC_NOT_ALLOCATED</code></td><td>The A/B Test is running, but<br>the user was not allocated to the test.</td><td>A (Control Group)</td></tr><tr><td><code>TRAFFIC_ALLOCATED</code></td><td>The user has been allocated to the A/B Test.</td><td>Allocated group</td></tr><tr><td><code>VARIATION_DROPPED</code></td><td>The originally allocated group has been removed from the test.</td><td>A (Control Group)</td></tr><tr><td><code>INVALID_INPUT</code></td><td>The input value is invalid.</td><td>A (Control Group)</td></tr><tr><td><code>EXCEPTION</code></td><td>An unknown error occurred.</td><td>A (Control Group)</td></tr></tbody></table>

### Parameters

* You can also receive the parameter values for the assigned Variation through the `variationDetail()` method.
* The `Decision` instance returned by `variationDetail()` contains a `ParameterConfig` object with the full parameter configuration.
* Since parameter values configured in the Hackle A/B Test screen are stored as key-value pairs, use the methods below according to the parameter type to retrieve the configured values.
* Use the following functions to retrieve the values configured for the assigned Variation.

<table data-header-hidden><thead><tr><th width="136.12109375">Method</th><th>Description</th></tr></thead><tbody><tr><td><code>getString</code></td><td>Returns parameter values configured as STRING or JSON type.</td></tr><tr><td><code>getInt</code></td><td>Returns parameter values configured as NUMBER type as an Int.</td></tr><tr><td><code>getDouble</code></td><td>Returns parameter values configured as NUMBER type as a Double.</td></tr><tr><td><code>getBool</code></td><td>Returns parameter values configured as Boolean type.</td></tr></tbody></table>

#### Example

```dart
import "package:hackle/hackle.dart";

Decision decision = await HackleApp.variationDetail(42);
ParameterConfig config = decision.config;

String strValue = config.getString("parameter_key_string_type", "defaultValue");
String jsonValue = config.getString("parameter_key_json_type", "defaultValue");
int intValue = config.getInt("parameter_key_number_type", 0);
double doubleValue = config.getDouble("parameter_key_number_type", 0.0);
bool boolValue = config.getBool("parameter_key_boolean_type", false);
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/flutter/flutter-variation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
