When trying to collect from a Flow the type suddenly mismatches, and it was working and then started suddenly.
在我的viewmodel中:
class MyViewModel: ViewModel() {
lateinit var river: Flow<Int>
fun doStuff() {
river = flow {
emit(1)
}.flowOn(Dispatchers.Default)
.catch {
emit(0)
}
}
}
在我的活动中,我有以下几点:
lifecycleScope.launch {
viewModel.river.collect { it ->
// this whole collect is what has the error.
}
}
But collect
gives the error: Type mismatch: inferred type is () -> Unit but FlowCollector<Int> was expected
.
这怎么会发生?