Tin Tran
09/17/2021, 7:53 AMTextFieldValue
var text by remember { mutableStateOf("") }
TextField(value = TextFieldValue(text), onValueChange = {text = it.text})
Felix Schütz
09/17/2021, 7:55 AMTextFieldValue
as state, like so:
mutableStateOf(TextFieldValue(""))
Filip Wiesner
09/17/2021, 7:57 AMTin Tran
09/17/2021, 7:58 AMTin Tran
09/17/2021, 8:19 AMTextField
source code in order to use TextFieldValue
they created a remembered state like you mentioned above but they have to copy it to another variable to use it. Does anyone know why?
var textFieldValueState by remember { mutableStateOf(TextFieldValue(text = value)) }
val textFieldValue = textFieldValueState.copy(text = value)
TextField(
enabled = enabled,
readOnly = readOnly,
value = textFieldValue,
onValueChange = {
textFieldValueState = it
if (value != it.text) {
onValueChange(it.text)
}
},
modifier = modifier,
singleLine = singleLine,
textStyle = textStyle,
label = label,
placeholder = placeholder,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
isError = isError,
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
maxLines = maxLines,
interactionSource = interactionSource,
shape = shape,
colors = colors
)Felix Schütz
09/17/2021, 8:26 AMonValueChange
by e.g. capitalizing the value. I think that the updated value wouldn't be reflected in the TextFieldValue
without the copying.Tin Tran
09/17/2021, 8:32 AMvalue
is updated, the remembered TextFieldValue
will be updated either but apparently it’s not the case.