我在一个协程中尝试了 init 三个集合,但只工作了第一个。只有当我设置在不同的协程中收集它的工作时。为什么?
lifecycleScope.launch {
launch {
homeViewModel.dateStateFlow().collect { date ->
date?.let { calendar.text = date.toStringForView() }
}
}
launch {
homeViewModel.toStateFlow().collect { to ->
to?.let { cityTo.text = to.name }
}
}
launch {
homeViewModel.fromStateFlow().collect { from ->
from?.let { cityFrom.text = from.name }
}
}
}