Feature

sealed interface 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
)
)

Checking Feature State

@Composable
fun MyScreen() {
val featureHandler = LocalFeatureHandler.current
val isDarkModeEnabled by featureHandler.isFeatureEnabled("dark_mode")

if (isDarkModeEnabled) {
DarkTheme { Content() }
} else {
LightTheme { Content() }
}
}

See also

Inheritors

Types

Link copied to clipboard
object Companion
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.

Properties

Link copied to clipboard
abstract val description: String?

Optional description explaining what this feature does.

Link copied to clipboard
abstract val isEnabled: Boolean

Whether the feature is currently enabled.

Link copied to clipboard
abstract val name: String

The unique identifier name of the feature.