Feature
Sealed interface representing a feature flag in the application.
Feature flags (also known as feature toggles) allow you to enable or disable features in your application without deploying new code. This sealed class provides two implementations:
LocalFeature: Simple device-local flags stored using DataStore
RemoteFeature: Flags controlled by remote configuration with local override capability
Usage
Defining Features
val features = listOf(
Feature.LocalFeature(
name = "dark_mode",
description = "Enable dark theme",
isEnabled = false
),
Feature.RemoteFeature(
name = "new_checkout",
description = "New checkout flow",
defaultRemoteValue = true,
state = FeatureState.REMOTE
)
)Content copied to clipboard
Checking Feature State
@Composable
fun MyScreen() {
val featureHandler = LocalFeatureHandler.current
val isDarkModeEnabled by featureHandler.isFeatureEnabled("dark_mode")
if (isDarkModeEnabled) {
DarkTheme { Content() }
} else {
LightTheme { Content() }
}
}Content copied to clipboard
See also
Inheritors
Types
Link copied to clipboard
data class LocalFeature(val name: String, val description: String?, val isEnabled: Boolean) : Feature
A locally-managed feature flag stored on the device.
Link copied to clipboard
data class RemoteFeature(val name: String, val description: String?, val defaultRemoteValue: Boolean, val state: FeatureState) : Feature
A feature flag controlled by a remote configuration service with local override capability.