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.

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.

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

Decision Reason
Description
Distribution Result

SDK_NOT_READY

The SDK is not ready to use. (e.g., initialization attempted with an invalid SDK Key)

Default state (off)

FEATURE_FLAG_NOT_FOUND

No Feature Flag was found for the provided Feature Key. The Feature Key may be incorrect, or the Feature Flag may be archived.

Default state (off)

FEATURE_FLAG_INACTIVE

The Feature Flag is in the off state.

Default state (off)

INDIVIDUAL_TARGET_MATCH

Matched by Individual Targeting.

State configured by Individual Targeting

TARGET_RULE_MATCH

Matched by User Targeting.

State configured by User Targeting

DEFAULT_RULE

Did not match either Individual Targeting or User Targeting.

State configured by default rule

EXCEPTION

An unknown error occurred.

Default state (off)

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.

getInt

  • Returns parameter values configured as Number type as an int.

  • Returns the value configured for False or True based on the state decision.

getDouble

  • Returns parameter values configured as Number type as a double.

  • Returns the value configured for False or True based on the state decision.

getBool

  • Returns parameter values configured as Boolean type.

  • Returns the value configured for False or True based on the state decision.

Last updated