https://kotlinlang.org logo
d

Denis

02/07/2021, 6:56 AM
I copy a `mutableStateListOf` example from docs without any changes, but it doesn't seem to work. AFAIU it should add new names, but the list on the screen stays empty. If I change it to
var names = remember { mutableStateListOf<String>() }
it starts to work. Is it a mistake in docs or am I doing/expecting something wrong?
Code from the link:
Copy code
@Composable
fun Names() {
    var name by remember { mutableStateOf("user") }
    val names = mutableStateListOf<String>()

    Column {
        Row {
            BasicTextField(
                value = name,
                onValueChange = { name = it }
            )
            Button(onClick = { names.add(name) }) {
                Text("Add")
            }
        }
        Text("Added names:")
        Column {
            for (addedName in names) {
                Text(addedName)
            }
        }
    }
}
j

jim

02/07/2021, 7:19 AM
🤦
cc @nickbutcher
n

nickbutcher

02/08/2021, 11:42 AM
d

Denis

02/08/2021, 1:53 PM
I did not. Nick, thank you for fixing it! And Jim thanks for your help too :)