---
title: Forced Decision methods for the Flutter SDK
slug: feature-experimentation/docs/forced-decision-methods-flutter
docTags: 
createdAt: 2026-08-05T20:39:58.000Z
---

Use these methods to test and debug various flows of your client applications by forcing users into a specific variation.

The Flutter SDK checks if any Forced Decision methods were implemented before making any decisions. If it finds a match for the requested flag, the Flutter SDK returns the forced decision immediately ([audience conditions](docId\:UDBvr5a8WHNkyOqzPhOr9) and traffic allocations are ignored) before making normal decisions.

The Flutter SDK checks for forced decisions at the start of each decision process. If a matching forced decision is found, it returns the decision immediately.

- **Flag-to-Decision** – The SDK checks at the start of any decide call for the given flag.
- **Experiment-Rule-to-Decision** – The SDK checks at the start of the decision for the given experiment rule of the flag key.
- **Delivery-Rule-to-Decision** – The SDK checks at the start of the decision for the given delivery rule of the flag key.

:::hint{type="danger"}
**Warning**
You must associate your variations to a [flag rule](docId:-yq2-thNRv7-SgwCXpG90) before calling any Forced Decision methods.
:::

On forced decisions, SDK fires impression events and notifications just like other normal decisions (unless disabled by the [disableDecisionEvent](docId\:Z93N-8Id5mLeEX7AEAh11) option).

:::hint{type="info"}
**Note**
These forced decisions are not persistent and the system clears them when the [OptimizelyUserContext](docId\:qkagdzXifMComMybuU4ls) is reinitialized.
:::

For information about each Forced Decision method, click on the method name.

- [\`setForcedDecision()\`](docId:4zhP0aWuAowrcUZUpfiUg)
- [\`getForcedDecision()\`](docId:4zhP0aWuAowrcUZUpfiUg)
- [\`removeForcedDecision()\`](docId:4zhP0aWuAowrcUZUpfiUg)
- [\`removeAllForcedDecisions()\`](docId:4zhP0aWuAowrcUZUpfiUg)

### OptimizelyDecisionContext

```dart
class OptimizelyDecisionContext {
  String flagKey;
  String? ruleKey;

  OptimizelyDecisionContext(this.flagKey, [this.ruleKey]);
}
```

### OptimizelyForcedDecision

```dart
class OptimizelyForcedDecision {
  String variationKey;

  OptimizelyForcedDecision(this.variationKey);
}
```

## Set Forced Decision method – `setForcedDecision()`

### Version

1.0.1 or higher

### Description

Sets a forced decision (`variationKey`) for a given `OptimizelyDecisionContext`.

### Parameters

This table lists the required and optional parameters for the Flutter SDK.

| Parameter                  | Type  | Description                                                                                                                                  |
| -------------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\*   | Class | An instance of \`OptimizelyDecisionContext\` with the required \`flagKey\` and optional \`ruleKey\` for the forced decision you want to set. |
| **decision**\ \*required\* | Class | An instance of \`OptimizelyForcedDecision\` with the required \`variationKey\` for the forced decision you want to set.                      |

### Returns

A boolean value that indicates if setting the forced decision (`variationKey`) was completed.

### Example

See the [Full code example section](docId:4zhP0aWuAowrcUZUpfiUg).

## Get Forced Decision method – `getForcedDecision()`

### Version

1.0.1 or higher

### Description

Returns the forced decision (`variationKey`) for a given `OptimizelyDecisionContext`. Returns the `OptimizelyForcedDecision` instance or null if there is no matching item.

### Parameters

This table lists the required and optional parameters for the Flutter SDK.

| Parameter                | Type  | Description                                                                                                                                  |
| ------------------------ | ----- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\* | Class | An instance of \`OptimizelyDecisionContext\` with the required \`flagKey\` and optional \`ruleKey\` for the forced decision you want to get. |

### Returns

A forced decision `OptimizelyForcedDecision` instance for the context or null if there is no matching item.

### Example

See the [Full code example section](docId:4zhP0aWuAowrcUZUpfiUg).

## Remove Forced Decision method – `removeForcedDecision()`

### Version

1.0.1 or higher

### Description

Removes the forced decision (`variationKey`) for a given `OptimizelyDecisionContext`.

### Parameters

This table lists the required and optional parameters for the Flutter SDK.

| Parameters               | Type  | Description                                                                                                                                     |
| ------------------------ | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| **context** \*required\* | Class | An instance of \`OptimizelyDecisionContext\` with the required \`flagKey\` and optional \`ruleKey\` for the forced decision you want to remove. |

### Returns

A success or failure boolean status if the forced decision (`variationKey`) was removed.

### Example

See the [Full code example section](docId:4zhP0aWuAowrcUZUpfiUg).

## Remove all forced decisions method - `removeAllForcedDecisions()`

### Version

1.0.1 or higher

### Description

Removes all forced decisions (`variationKey`) for the user context.

### Parameters

This table lists the required and optional parameters for the Flutter SDK.

| Parameters | Type | Description |
| ---------- | ---- | ----------- |
| None       | N/A  | N/A         |

### Returns

A success or failure boolean status.

### Example

See the [Full code example section](docId:4zhP0aWuAowrcUZUpfiUg).

## Full code example

```dart
/* Create the OptimizelyUserContext, passing in the UserId and Attributes */
var user = await optimizelyClient.createUserContext(userId: "user-id");

var flagContext = OptimizelyDecisionContext("flag-1");
var flagAndABTestContext = OptimizelyDecisionContext("flag-1", "exp-1");
var flagAndDeliveryRuleContext = OptimizelyDecisionContext("flag-1", "delivery-1");
var variationAForcedDecision = OptimizelyForcedDecision("variation-a");
var variationBForcedDecision = OptimizelyForcedDecision("variation-b");
var variationOnForcedDecision = OptimizelyForcedDecision("on");

// set a forced decision for a flag
var success = await user!.setForcedDecision(flagContext, variationAForcedDecision);
var decision = await user.decide("flag-1");

// set a forced decision for an ab-test rule
success = await user.setForcedDecision(flagAndABTestContext, variationBForcedDecision);
decision = await user.decide("flag-1");

// set a forced variation for a delivery rule
success = await user.setForcedDecision(flagAndDeliveryRuleContext, variationOnForcedDecision);
decision = await user.decide("flag-1");

// get forced variations
var forcedDecision = await user.getForcedDecision(flagContext);
print("[ForcedDecision] variationKey = ${forcedDecision.variationKey}");

// remove forced variations
success = await user.removeForcedDecision(flagAndABTestContext);
success = await user.removeAllForcedDecisions();
```

## See Also

[OptimizelyUserContext](docId\:qkagdzXifMComMybuU4ls)

## Source files

The language and platform source files containing the implementation for Flutter are available on GitHub.

- Flutter Android – [Optimizely.java](https://github.com/optimizely/java-sdk/blob/master/core-api/src/main/java/com/optimizely/ab/Optimizely.java).
- Flutter iOS – [OptimizelyClient.swift](https://github.com/optimizely/swift-sdk/blob/master/Sources/Optimizely/OptimizelyClient.swift).
