Im creating a Flow inside my repository which fetches data from an sse api
override fun getStream() = flow {
try {
val response = api.getStream()
while (true) {
//do something with response
emit(result)
}
} catch (e: HttpException) {
..
}
}
It get forwarded into my composable where the viewmodel gets injected
@Composable
fun FirstPage(
viewmodel: myviewmodel = hiltViewModel()
)
The flow then gets collected like this
val eventStream by viewmodel.getStream().collectAsState(initial = "Loading"))
But in this scenario, the flow does not get collected. If i emit something before the try block, the value will show, but nothing from inside of it.
I know the api call is working, because when i collect the flow inside my viewmodel, the data shows.