Tried to use collectAsStateWithLifecycle() in comm...
# multiplatform
n
Tried to use collectAsStateWithLifecycle() in commonMain as shown in @Sebastian Aigner's talk, but facing this issue with jetbrain's lifecycle version 2.8.0, this issue is solved in androidx's lifecycle version 2.8.2, is there a way to solve this without any work around ?
a
You need a workaround or wait until Compose 1.7.0 is released. You can create a new extension function with:
Copy code
@Composable
fun <T> StateFlow<T>.collectAsStateWithLifecycle(): State<S> =
    collectAsStateWithLifecycle(
        lifecycleOwner = androidx.compose.ui.platform.LocalLifecycleOwner.current,
    )
👍 2
n
Thanks, will try this method
t
I just ran into this myself (builds on iOS, but not Android), and that code above does not work...
Never mind. I was missing the
Copy code
implementation(libs.jetbrains.lifecycle.runtime.compose)
line.