Three ways this can be resolved are
-
- To call the method in a launched effect block in your composable
-
- Or set the Context to Dispatchers.Main when setting value of the mutableState using withContext(Dispatchers.Main)
-
- Or change the mutable state in viewModel to mutableState flow and use collectAsState() in composable to collect it as a state.