Remote Config¶
The Starter Template includes a type-safe Remote Config system built using Clean Architecture.
It allows you to:
- Define strongly typed keys
- Provide safe defaults
- Deserialize custom JSON objects
- Use values in ViewModels or Compose
- Replace Firebase with your own implementation
Keys¶
You can define all your keys inside:
Note
- It's recommended to set default value by
override - Keys must exactly match Firebase console keys.
- Always provide safe default values.
- Use a serializer for custom objects.
Initialization
Remote Config must be initialized at app startup:
This is already called in the entry point by default.
Warning
Make sure Firebase is integrated correctly because the default implementation uses Firebase Remote Config internally.
Example – Enable/Disable Ads¶
Let’s say you want to remotely enable/disable ads.
ViewModel¶
Now your UI can decide whether to show ads dynamically without releasing a new version.
Example – Running a Promotion¶
Suppose you want to run a limited-time discount campaign.
ViewModel¶
class PromoViewModel(
private val getConfig: GetConfigLogic
) : ViewModel() {
private val _promo = MutableStateFlow(RemoteConfigKeys.Promo())
val promo: StateFlow<RemoteConfigKeys.Promo> = _promo
init {
viewModelScope.launch {
_promo.value =
getConfig(RemoteConfigKeys.Promo())
}
}
}
Now you can:
- Enable/disable the campaign remotely
- Change discount percentage
- Avoid app updates for marketing changes
Compose Usage¶
You can directly use Remote Config inside Compose:
- Starts with default value
- Updates automatically after fetch
- Supports primitives & custom types
Custom Implementation¶
If you don’t want Firebase (or for testing), create your own repository in:
Interface¶
Here, RemoteConfigValue is a typealias:
Local Implementation Example¶
Bind it in Koin:
| features/remote_config/data/commonMain/.../di/Module.kt | |
|---|---|
This is useful for:
- Unit testing
- Desktop builds
- CI pipelines
- Offline development
Summary
- Define keys in
RemoteConfigKeys.kt - Always provide default values
- Use
GetConfigLogicin ViewModels - Use
rememberRemoteConfigin Compose - Replace repository if needed