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

Apache License 2.0
61 stars 97 forks source link

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

Open uDanielBispo opened 3 months ago

uDanielBispo commented 3 months 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#4

In which task and step of the codelab can this issue be found? Intro to state in Compose

Describe the problem Hi! I do not really know if it is a problem, however I was following the step by step of this process and I have found a litlle problem: image

In the codelab it says that you can use this code, but I got an error that prevented me to build the app, may be something that changed in the mean time that the codelab was created and I have satarted, anyway if it is not a problem, ok.

I already tried to use .value, still not working

I expect being useful

Steps to reproduce?

  1. it's just use the code on this codelab, it isn't working

Versions Android Studio version: sorry, i am new on this, can't say API version of the emulator: sorry, i am new on this, can't say

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

MohammedRAbed commented 3 months ago

Maybe this is because you're initializing it inside a Composable function. It'll work with no errors if you initialize it in a not-composable one, otherwise, you'll need to do it with the remember function. PS: You might want to take a look at Understanding state in Compose from Interacting with UI and State pathway.