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 #110

Open Arthur-Milchior opened 1 year ago

Arthur-Milchior 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#4

In which task and step of the codelab can this issue be found? 5

Describe the problem

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf

var amountInput: MutableState<String> = mutableStateOf("0")

This part of the code, that appears in the codelab, seems to indicate that amountInput should be a static value that appear at the top level. This is even more confusing because, in this case, the code actually works as expected, value is remembered during recomposition.

So it would be better to separately state to use a mutableState and to import those packages

android-dev-lxl commented 1 year ago

@Arthur-Milchior We appreciate you bringing this issue to our attention. Could you please explain the issue further, are import statements confusing?