Skip to content

NavArgs: boolean with default value breaks deeplinks #772

@cwsiteplan

Description

@cwsiteplan

Not sure if this was discussed already

data class MyNavArgs(
    ...
    val myBoolean: Boolean = null,
) 

AI summary:

  1. booleanNavType is typed as DestinationsNavType<Boolean?> (nullable)
  2. When a Boolean nav arg has a default value (= false), KSP
    correctly sets defaultValue = false in the navArgument block
  3. But in the generated argsFrom(bundle) method, it generates:
  myBoolean = booleanNavType.safeGet(bundle, "myBoolean") ?: throw RuntimeException("... not present!")               
  1. When navigating via deep link (which doesn't include
    myBoolean in the URL), the Navigation framework should supply the default, but booleanNavType.safeGet() can return null when the value isn't in the bundle — triggering the crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions