Thread
#compose
    amar_1995

    amar_1995

    2 years ago
    I am using simple
    TextField
    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 })
                }
                
            }
        }
    }
    b

    bmo

    2 years ago
    I believe it should be like this :
    @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

    amar_1995

    2 years ago
    What is a difference between
    +state
    and
    by state
    Adam Powell

    Adam Powell

    2 years ago
    Not having to type
    .value
    when using it
    Still need the + either way though
    Muhammad Usman

    Muhammad Usman

    2 years ago
    @bmo I am creating simple edittext , i tried your composable fun but it says Type Effect<State<Stromg>> has no metheds getValue and set value on var textState by state{ text }
    amar_1995

    amar_1995

    2 years ago
    @Muhammad Usman I am recieving the same error
    Try using this
    var textState by +state{ "" }
    And as @Adam Powell suggested you don't have to use
    .value
    while calling textFeild
    Muhammad Usman

    Muhammad Usman

    2 years ago
    @amar_1995 thanks
    amar_1995

    amar_1995

    2 years ago
    But still the problem exist cannot able to get userInput.
    If I turn on this show virtual keyboard option. I am getting this error.
    kotlin.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)
    I beleive there is some issue with textFeild. Tried the sample code as writen in google
    ui-framework-integration-tests-sample
    @Sampled
    @Composable
    fun EditorModelTextFieldSample() {
        val state = +state { EditorModel() }
        TextField(
            value = state.value,
            onValueChange = { state.value = it }
        )
    }
    b

    bmo

    2 years ago
    @amar_1995 I have used it in my sample app : https://github.com/bmonjoie/ComposeTipsCalculator/blob/master/app/src/main/java/be/xzan/composetipscalculator/HintedTextField.kt It does work but I didn't use a
    state
    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

    amar_1995

    2 years ago
    I see, you was using
    @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 ?
    b

    bmo

    2 years ago
    I have had issue with
    state
    and I used
    stateFor
    to fix that but no clue why to be honest ¯_(ツ)_/¯
    amar_1995

    amar_1995

    2 years ago
    I tried using
    stateFor
    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 ?
    b

    bmo

    2 years ago
    @amar_1995 You need to pass a value in the
    ()
    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

    amar_1995

    2 years ago
    It is now working for me. Issue is with the emulator, I was using genymotion emulator. But after running it in normal avd emulator it is working. Seems like there is some configuration issue with genymotion emulator.