https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
v

Vaibhav Jaiswal

09/25/2023, 2:57 PM
@veyndan I am using multiplatform paging 3.2.0-alpha05, I am unable to access any of the extension functions defined on PagingData (map, filter, cachedIn, etc) in CommonMain
v

veyndan

09/25/2023, 3:14 PM
Are you importing the functions (e.g.,
app.cash.paging.map
)?
v

Vaibhav Jaiswal

09/25/2023, 3:52 PM
yes
the autocomplete does not show, I tried adding import, still doesnt recognize
For a workaround, i have created expect functions of my own, and in the actual implementations, i can access the extension functions
v

veyndan

09/25/2023, 4:05 PM
The autocomplete is a known issue and is gonna be fixed in an upcoming version of IntelliJ https://github.com/cashapp/multiplatform-paging/issues/5#issuecomment-1373821709
I just tested out the import locally and it works fine. Do you have a reproducible sample?
v

Vaibhav Jaiswal

09/25/2023, 4:18 PM
Copy code
import app.cash.paging.insertHeaderItem
import app.cash.paging.map
import app.cash.paging.PagingData
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map

class TestViewModel  {

    val value = flow<PagingData<Int>> {
        emit(PagingData.empty<String>())
    }.map {
        it.map { it.toInt() }
    }
    
    val value2 = flow<PagingData<String>> {
        emit(PagingData.empty<String>())
    }.map {
        it.insertHeaderItem(item = "Header")
    }
}
insertHeaderItem and map are shown in red, with this error
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
v

veyndan

09/25/2023, 4:20 PM
If you run
./gradlew build
from the terminal, does that pass or fail?
v

Vaibhav Jaiswal

09/25/2023, 4:28 PM
it failed, but when I remove the generic type and keep it like
Copy code
flow {}
it does not show any error and builds correctly
if I define the type like
Copy code
val value:Flow<PagingData<Int>>
IDE shows error, but builds fine
this is where I’m facing the issue, same map, insertHeaderItem and cachedIn shown in red, its building correctly though
Copy code
val sourceData = newsRepo.getSourcesList()
        .pagedData
        .map { it.map { FilterModel.SourceModel(it) as FilterModel } }
        .map { it.insertHeaderItem(item = FilterModel.SourceHeader) }

private fun getNewsPaged() = newsRepo.getNews(sourceFilters).pagedData
        .cachedIn(coroutineScope)
        .onStart { newsRepo.clearAllNews() }
        .onEach { _newsData.emit(it) }
        .onEach { mutableState.emit(State.Success) }
        .launchIn(coroutineScope)
v

veyndan

09/25/2023, 4:36 PM
You shouldn't trust the IDE. It'll often show up in red even though it compiles fine because of https://github.com/cashapp/multiplatform-paging/issues/5#issuecomment-1373821709. The only way to get around this is to wait until IntelliJ releases a new version that fixes it
You said that
./gradlew build
is failing, which is more concerning. Do you mind also sharing your
build.gradle[.kts]
file?
v

Vaibhav Jaiswal

09/25/2023, 4:40 PM
The build failing was a silly mistake, i wrote wrong syntax 😅
Thanks a lot for the help
v

veyndan

09/25/2023, 4:43 PM
Ah gotcha! And no worries 😄 Just a FYI that someone from the JetBrains team reached out to me about this IDE issue, and they said they have a patch to fix it and verified that it fixes this issue in Multiplatform Paging. I don't know anything about the time frame on when the fix will be released though!
2 Views