Trying use paging 3 lib with filter I cannot expla...
# android
c
Trying use paging 3 lib with filter I cannot explain why it crashed if I don’t insert in between .cachedIn(viewModelScope)
Copy code
val repoResult: Flow<PagingData<Repo>> = queryFlow.filterNotNull()
        .flatMapLatest { query ->
            repository.getSearchResultStream(query)
        }
        //.cachedIn(viewModelScope) //crash without
        .combine(filterFlow) { page, filter ->
            page.filter {
                it.description?.contains(filter, true) ?: false
            }
        }

    lifecycleScope.launch {
            viewModel.repoResult.collectLatest {
                adapter.submitData(it)
            }
    }

crash is java.lang.IllegalStateException: Attempt to collect twice from pageEventFlow, which is an illegal operation. Did you forget to call Flow<PagingData<*>>.cachedIn(coroutineScope)?
i
It seems you are trying to call it twice
c
adapter.submitData is called every time the filter changes doing a local filter of the network data, second time is causing the crash even it’s in a collectLatest. it should be only one active collector on pagedata, however this doesn’t work I find pagedata to be fragile and too encapsulated
629 Views