Feature Flag Determination
A feature flag has an on and off state. You will set different features according to each state.
Once a feature flag is applied, a specific user from your traffic should be able to either receive an off or on status. This on/off status determination can be done through the Hackle SDK.
IsFeatureOn
You can pass a feature key to the isFeatureOn()
method to receive status results for the user. After receiving the status, we can then implement the logic according to each status.
In the example code below, we are passing feature key 42.
import "package:hackle/hackle.dart";
// Determines the status of the feature flag to assign users with a feature key of 42.
// For undetermined cases, users are assigned to false (off status).
bool featureOn = await HackleApp.isFeatureOn(42);
if (featureOn) {
// Logic for on status
} else {
// Logic for off status
}
FeatureFlagDetail
The feature_flag_detail()
method works like the IsFeatureOn()
method but additionally provides a reason for determining the status of a particular user. This can be useful when you want to check whether the manual allocation is working well or when you think that the traffic allocation you have set is not being reflected in your results.
You must pass a feature key as a parameter. For the example code below, we are passing feature key 42.
import "package:hackle/hackle.dart";
// Status determination details
FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
// Feature flag on/off results
bool featureOn = decision.isOn;
// Reason for status determination
DecisionReason reason = decision.reason;
Please refer to the table below for the full list of reasons for different status determinations.
Reason | Description | Feature Status |
---|---|---|
SDK_NOT_READY | The SDK is not ready to use. (e.g. trying to initialize with the wrong SDK key) | Default status(off) |
FEATURE_FLAG_NOT_FOUND | No feature flags were found for the function key you passed in. The feature key may be incorrect or the corresponding feature flag may be in an archived state. | Default status(off) |
FEATURE_FLAG_INACTIVE | The feature flag is off. | Default status(off) |
INDIVIDUAL_TARGET_MATCH | User has been matched to individual targeting settings. | Set to individual targeting |
TARGET_RULE_MATCH | User has been matched to audience targeting settings. | Set to audience targeting |
DEFAULT_RULE | User has not been matched to either individual targeting or audience targeting. | Default status (off) |
INVALID_INPUT | The input value is not valid. (e.g., Enter the character type in the parameter where the number type should be entered) | Default status(off) |
EXCEPTION | An unknown error has occurred. | Default status(off) |
Feature Flag Parameter
- Call
featureFlagDetail()
method to obtain parameter values which contains the feature flag status information FeatureFlagDecision
instance passed through thefeatureFlagDetail()
method has full parameter setting information.- Parameter values you've set on the dashboard exists in the form of key and value, therefore you can use the method below to set the parameter values.
- You can change feature flag's parameter values flexibly on the Feature Flag > Parameter Settings.
getString
- Returns the parameter value set to STRING, JSON type.
- Returns the default value or the value set in the rule based on the status determination.
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 the parameter value set to Number type as Int type.
- Returns the default value or the value set in the rule based on the status determination.
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 the parameter value set to Number type as Double type.
- Returns the default value or the value set in the rule based on the status determination.
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);
getBoolean
- Returns the parameter value set to Boolean type.
- Returns the default value or the value set in the rule based on the status determination.
import "package:hackle/hackle.dart";
FeatureFlagDecision decision = await HackleApp.featureFlagDetail(42);
ParameterConfig config = decision.config;
bool boolValue = config.getBool("parameter_key_boolean_type", false);
Updated almost 2 years ago