Function invocation 'map(…)' expected in navigation component

Issue

I’m using the android navigation component from quite sometime and very much aware of how to pass data using safe nav arguments but today getting some unexpected errors in navArgs generated files.

Getting these errors: (Also attaching Screenshot)

  1. Function invocation ‘map(…)’ expected
  2. No value passed for parameter ‘transform’.
  3. Type mismatch: inferred type is List but Array? was expected
  4. Unresolved reference: it

i am using the following depencdencies:

def nav_version = "2.5.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

kotlin_version = '1.7.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0-alpha04'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0-alpha04'

Navigation Graph

  <argument
        android:name="bulkForwardPackages"
        app:argType="app.px.packagex.models.domainmodels.MemberPackageItemDomainModel[]" />

Any.kt

navigate(DashboardListingFragmentDirections.actionDashboardListingFragmentToBulkForwardPackages(
                    listOf(memberPackage).toTypedArray(),
                    getMemberDetailsFromPackage(memberPackage)
                )
            )

Model class

@Parcelize
data class MemberPackageItemDomainModel(
val packageId: Int = 0,
val memberId: Int = 0,
val building_id: Int = 0,
val mailroom_id: Int = 0,
val createdAt: String = "",
val created_by: String = "",
....
): Parcelable {}

enter image description here

Any Help regrading this will be highly appreciated. Thanks

Solution

This is a known issue when using an argument with an android:name of exactly 19 characters long – the generated code line breaks exactly where it is illegal to line break in Kotlin (the { needs to be on the same line).

Changing the name to either be a few characters shorter or a few characters longer would work around this issue.

Answered By – ianhanniballake

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published