isEnabled method

bool isEnabled(
  1. Feature feature
)

Determines if the given feature is enabled.

The function checks if the feature's value type is FeatureValueType.toggle. If it is, the function retrieves the boolean value associated with the feature's key from the shared preferences. If the value is not found, it returns the default value of the feature if it is of type bool. If the default value is not available, it returns false. If the feature's value type is not FeatureValueType.toggle, the function returns false.

Parameters:

  • feature: The Feature object to check.

Returns:

  • bool: true if the feature is enabled, false otherwise.

Implementation

bool isEnabled(Feature feature) {
  if (feature.valueType == FeatureValueType.toggle) {
    return _sharedPreferences.getBool(feature.key) ??
        feature.defaultValue as bool? ??
        false;
  } else {
    return false;
  }
}