# Feature Flag Decision

A Feature Flag has two states: on and off. Different features are configured for each state. When a user accesses a feature with a Feature Flag applied, the SDK must be able to return either the on or off state. You can use the Hackle SDK to handle this state decision.

## isFeatureOn

Pass the **Feature Key** to the `isFeatureOn()` method to receive the state result for the user. Then implement logic based on the state.

In the example code below, Feature Key 42 is passed.

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

// Determines the user's state for the Feature Flag with Feature Key 42.
// Returns false (off state) if a decision cannot be made.
bool featureOn = await HackleApp.isFeatureOn(42);

if (featureOn) {
    // ON feature
} else {
    // OFF feature
}
```

## featureFlagDetail

The `featureFlagDetail()` method works the same as `isFeatureOn()` but additionally provides the reason for the state decision. This is useful for verifying that Override is working correctly or when the result proportion seems inconsistent with the configured Traffic Allocation.

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

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

// Feature Flag Decision detail
FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);

// Feature on/off status
bool featureOn = decision.isOn;

// Decision reason
DecisionReason 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="233.71875">Decision Reason</th><th width="370.8046875">Description</th><th>Distribution Result</th></tr></thead><tbody><tr><td><code>SDK_NOT_READY</code></td><td>The SDK is not ready to use.<br>(e.g., initialization attempted with an invalid SDK Key)</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_NOT_FOUND</code></td><td>No Feature Flag was found for the provided Feature Key.<br>The Feature Key may be incorrect, or the Feature Flag may be archived.</td><td>Default state<br>(off)</td></tr><tr><td><code>FEATURE_FLAG_INACTIVE</code></td><td>The Feature Flag is in the off state.</td><td>Default state<br>(off)</td></tr><tr><td><code>INDIVIDUAL_TARGET_MATCH</code></td><td>Matched by Individual Targeting.</td><td>State configured by<br>Individual Targeting</td></tr><tr><td><code>TARGET_RULE_MATCH</code></td><td>Matched by User Targeting.</td><td>State configured by User Targeting</td></tr><tr><td><code>DEFAULT_RULE</code></td><td>Did not match either Individual Targeting or User Targeting.</td><td>State configured by<br>default rule</td></tr><tr><td><code>EXCEPTION</code></td><td>An unknown error occurred.</td><td>Default state<br>(off)</td></tr></tbody></table>

## Feature Flag Parameters

* You can also receive the parameter values for the state decision through the `featureFlagDetail()` method.
* The `FeatureFlagDecision` instance returned by `featureFlagDetail()` contains a `ParameterConfig` object with the full parameter configuration.
* Since parameter values configured in the Hackle Feature Flag screen are stored as key-value pairs, use the methods below according to the parameter type to retrieve the configured values.
* You can dynamically update values in the Feature Flag parameter configuration screen.

### getString

* Returns parameter values configured as STRING or JSON type.
* Returns the value configured for False or True based on the state decision.

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

FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
ParameterConfig config = decision.config;

String strValue = config.getString("parameter_key_string_type", "defaultValue");
String jsonValue = config.getString("parameter_key_json_type", "defaultValue");
```

### getInt

* Returns parameter values configured as Number type as an int.
* Returns the value configured for False or True based on the state decision.

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

FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
ParameterConfig config = decision.config;

int intValue = config.getInt("parameter_key_number_type", 0);
```

### getDouble

* Returns parameter values configured as Number type as a double.
* Returns the value configured for False or True based on the state decision.

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

FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
ParameterConfig config = decision.config;

double doubleValue = config.getDouble("parameter_key_number_type", 0.0);
```

### getBool

* Returns parameter values configured as Boolean type.
* Returns the value configured for False or True based on the state decision.

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

FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
ParameterConfig config = decision.config;

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-feature-flag.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.
