isFeatureEnabled static method
- BuildContext context,
- bool featureSelector(
- SdkFeatures features
- bool? failClosed,
- bool listen = true,
Helper to check if a specific feature is enabled by remote configuration.
Evaluates featureSelector against SdkFeatures if config is loaded.
If config has not loaded yet or failed to load:
- Returns false if failClosed is true (default).
- Returns true if failClosed is false.
Implementation
static bool isFeatureEnabled(
BuildContext context,
bool Function(SdkFeatures features) featureSelector, {
bool? failClosed,
bool listen = true,
}) {
final scope = listen
? context.dependOnInheritedWidgetOfExactType<CupThreadThemeScope>()
: (context.getInheritedWidgetOfExactType<CupThreadThemeScope>() ??
context.dependOnInheritedWidgetOfExactType<CupThreadThemeScope>());
final effectiveFailClosed = failClosed ?? scope?.failClosed ?? true;
if (scope == null) return !effectiveFailClosed;
if (scope.appConfig != null) {
return featureSelector(scope.appConfig!.sdk.features);
}
// Config is either still loading or errored
return !effectiveFailClosed;
}