google-developer-training / basic-android-kotlin-compose-training-tip-calculator

Apache License 2.0
60 stars 88 forks source link

Intro to state in Compose: Android Basics with Compose #98

Open tibolanneau opened 1 year ago

tibolanneau commented 1 year ago

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

In which task and step of the codelab can this issue be found? 11.2.1 "In TipTimeScreen() composable function, call the toDoubleOrNull function on the amountInput variable, to convert the String to a Double:"

Describe the problem it says in the TipTimeScreen() function but it is in the EditNumberField() function.

Steps to reproduce?

  1. Go to the TipTimeScreen() function
  2. Enter the code: "val amount = amountInput.toDoubleOrNull()"
  3. See error "Unresolved reference: amountInput"

Versions Android Studio version: flamingo API version of the emulator: 21 (5.0)

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

android-dev-lxl commented 1 year ago

@tibolanneau Thank you for reaching out to us. I think you missed a step. You need to Hoist the state; move the remembered state from the EditNumberField() function to the TipTimeLayout()function:

image