Skip to content

Navigate between screens with Compose: Android Basics with Compose #126

@buboj

Description

@buboj

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-navigation?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-2%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-navigation#4

In which task and step of the codelab can this issue be found?
Navigate between screens with Compose

Describe the problem
Navigation does not work with the provided code for the call of passed functions without parameters () -> Unit

Steps to reproduce?
The tutorial tells me to add this code on onClick of the the button in SelectOptionScreen.kt:

...
Button(
    modifier = Modifier.weight(1f),
    enabled = selectedValue.isNotEmpty(),
    onClick = onNextButtonClicked
) {
    Text(stringResource(R.string.next))
}
...

But this is not working, at least on my setup. I know, that kotlin generally allows function calls without empty parenthesis if there are no parameters needed. But it seems to need empty parenthesis here.
Because if I add them here:
onClick = onNextButtonClicked()
it works like it should!
It took me hours to spot this. Even Gemini did not spot this error, neither did the compiler.

Versions
Android Studio version:
Build #AI-251.25410.109.2511.13752376
API version of the emulator:
API 36

Additional information
Include screenshots if they would be useful in clarifying the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions