<How can I initialize a val that need to be initia...
# stackoverflow
r
How can I initialize a val that need to be initialize through viewModelScope? I have the below code class MainViewModel(private val todoDao: TodoDao) : ViewModel() { private var todoList = mutableStateListOf() private val _todoListFlow = MutableStateFlow(todoList) val todoListFlow: StateFlow get() = _todoListFlow private var postExecute: (() -> Unit)? = null init { loadTodoList() } private fun loadTodoList() { viewModelScope.launch { todoDao.getAll().collect { todoList = it.toMutableStateList()...