How to connect mutableStateFlow to Compose for des...
# compose-desktop
r
How to connect mutableStateFlow to Compose for desktop? I have a hot flow (from mqtt) that i would like to incorporate into Cards. As a self contained example:
Copy code
fun main() {
    val _state = MutableStateFlow("")
    val state = _state.asStateFlow()
    GlobalScope.launch {
        while (true) {
            _state.emit(Date().toString())
            delay(1000)
        }
    }
    GlobalScope.launch {
        state.collect {
            println("received $it")
        }
    }
    Window {
        var text by remember { mutableStateOf(state) }
        MaterialTheme {
            Text(text.value)
        }
    }

}
Whatever I try I either run into an exception that the state is out of sync. Or nothing works. I have searched the internet all over, but I have been unable to find anything that sheds any light on what I am trying to do.
👀 2
👍 1
a
Copy code
val text by state.collectAsState()
r
wow, why did I not find that!? works like a charm, thank you very much
👍 1