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)
- Function invocation 'map(...)' expected
- No value passed for parameter 'transform'.
- Type mismatch: inferred type is List but Array? was expected
- 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 {}
Any Help regrading this will be highly appreciated. Thanks
CodePudding user response:
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.