Iuhas Cezar
05/16/2022, 7:49 AMval textState = remember { mutableStateOf(costTextValue)}
but the value appears to be empty. If i print the value in log it shows correctly, but in my variable it's empty.Ji Sungbin
05/16/2022, 7:57 AMtextState
will be initialized with costTextValue
being received as an argument to the function.Ji Sungbin
05/16/2022, 7:59 AMColton Idle
05/16/2022, 7:59 AMval textState = remember { mutableStateOf(costTextValue)}
and just use costTextValue directly.Iuhas Cezar
05/16/2022, 8:03 AMmyanmarking
05/16/2022, 8:14 AMtextState.value = costTextState
after textState declarationIuhas Cezar
05/16/2022, 8:18 AMonValueChanged
I'm guessing because of recomposition, textState.value = costTextState
gets called again and resets it maybe.Oleksandr Balan
05/16/2022, 8:53 AMcostTextValue
is dynamic and firstly TextInputCost
is composed with costTextValue = ""
. This leads to creating an inner state textState
with this value. Then TextInputCost
is recomposed again with non-empty costTextValue
, but inner state is not updated with a new value because remember
has no keys.
Try to add a key to remember, so that inner state is recreated correctly:
val textState = remember(costTextValue) { mutableStateOf(costTextValue) }
Chris Fillmore
05/16/2022, 9:24 AMand it shows the correct value in the textfield but again it doesn’t change the value inWhat makes you say this? The value of the text field reflects updates toonValueChanged
textState
. So if your text field is updating, then your onValueChange
is working correctly.Chris Fillmore
05/16/2022, 9:26 AMcostTextValue
to initialCostTextValue
, because that is all it is, the initial value for textState
Iuhas Cezar
05/16/2022, 9:55 AMIuhas Cezar
05/16/2022, 9:58 AMcostTextValue
directly in the viewModel from onValueChange
Vsevolod Kaganovych
05/16/2022, 12:53 PMvar text by remember { mutableStateOf("") }
LaunchedEffect(*your initial word*) {
text = *your initial word*
}
Iuhas Cezar
05/16/2022, 1:11 PM