'Jetpack Compose - Unresolved reference: observeAsState
I'm learning Jetpack Compose and I was trying to make a View Model for my @Composable.
In documentation (https://developer.android.com/codelabs/jetpack-compose-state#3) for observing state changes in composable they use observeAsState but in my implementation, the method cannot be found. I get instead Unresolved reference: observeAsState
ViewModel
class MainActivityViewModel : ViewModel() {
val list: LiveData<MutableList<String>> = MutableLiveData(mutableListOf("Ana", "Are", "Mere"))
fun addString(item: String) {
val list: MutableList<String> = list.value!!
list.add(item)
}
}
I am using Compose 1.0.0-beta01
Solution 1:[1]
observeAsState is part of the runtime-livedata library.
Add the dependency to your module's build.gradle file. Replace $compose_version with the version of compose which you use, e.g. 1.0.0-beta01:
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
You can find the available versions here in Google's Maven repository.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

