amar_1995
11/13/2019, 12:41 PMTextField
to get userInput. But I am not able to write anything in TextFeild
@Composable
fun EditTextView(text: String) {
val textState = +state{ text }
Padding(left = 8.dp, top = 8.dp, right = 8.dp) {
Surface(
color = Color.Gray,
shape = RoundedCornerShape(8.dp)
) {
Padding(padding = 5.dp) {
TextField(value = textState.value,
onValueChange = { textState.value = it })
}
}
}
}
bmo
11/13/2019, 1:19 PM@Composable
fun EditTextView(text: String) {
var textState by state{ text }
Padding(left = 8.dp, top = 8.dp, right = 8.dp) {
Surface(
color = Color.Gray,
shape = RoundedCornerShape(8.dp)
) {
Padding(padding = 5.dp) {
TextField(value = textState,
onValueChange = { textState = it })
}
}
}
}
amar_1995
11/13/2019, 1:33 PM+state
and by state
Adam Powell
11/13/2019, 1:34 PM.value
when using itMuhammad Usman
11/14/2019, 5:33 AMamar_1995
11/14/2019, 5:46 AMvar textState by +state{ "" }
.value
while calling textFeildMuhammad Usman
11/14/2019, 5:57 AMamar_1995
11/14/2019, 6:07 AMkotlin.NotImplementedError: An operation is not implemented: not implemented
at androidx.ui.core.input.RecordingInputConnection.requestCursorUpdates(RecordingInputConnection.kt:244)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:527)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:93)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
ui-framework-integration-tests-sample
@Sampled
@Composable
fun EditorModelTextFieldSample() {
val state = +state { EditorModel() }
TextField(
value = state.value,
onValueChange = { state.value = it }
)
}
bmo
11/14/2019, 7:09 AMstate
for it. I'm propagating the value back up in order to change my model and then re-rendering the textfield with the value from my model :
https://github.com/bmonjoie/ComposeTipsCalculator/blob/master/app/src/main/java/be/xzan/composetipscalculator/MainActivity.kt
The reason I did that is if I stored the value in a state
within my method, there is no easy way for me to retrieve that value later (or none that I could think of).amar_1995
11/14/2019, 9:25 AM@Model
class and propagating value back up in order. In any change model will reload view.
But, I want to know why simple code of textFeild
not working using state. Is there any bug ?bmo
11/14/2019, 9:58 AMstate
and I used stateFor
to fix that but no clue why to be honest ¯\_(ツ)_/¯amar_1995
11/14/2019, 10:20 AMstateFor
but it is also not working.
val state =
+stateFor<String?>() { "sample1" }
MaterialTheme() {
TextField(value = state.value!!,
onValueChange = { state.value = it})
}
What am I doing wrong ?bmo
11/14/2019, 1:56 PM()
it can be a value that you pass to your function or a constant.
This should look like :
@Composable
fun EditTextView(text: String) {
val textState = +stateFor("sample1"){ text }
Padding(left = 8.dp, top = 8.dp, right = 8.dp) {
Surface(
color = Color.Gray,
shape = RoundedCornerShape(8.dp)
) {
Padding(padding = 5.dp) {
TextField(value = textState.value,
onValueChange = { textState.value = it })
}
}
}
}
amar_1995
11/14/2019, 2:02 PM