What is the correct way to pull text from a TextSt...
# compose
g
What is the correct way to pull text from a TextStringValue? It looks like sometimes the selection range works and sometimes it doesn’t . I either get no string or a string with a bunch of zeros at the beginning.
Copy code
@Composable
    override fun TextFieldStyled(
        text: String,
        onDone: (String) -> Unit,
        //,hint: String = "enter value"
        backgroundColor: Color,
        textColor : Color,
        height: Dp,
        keyboardType: KeyboardType,
        visualTransformation: VisualTransformation,
        cursorColor : Color
        ) {
        //val state = +state { "" }
        //state.value = if (loginInput.usernameEntered) loginInput.username else hint
        val state = state { TextFieldValue(text) }
        Surface(color = backgroundColor) { //}, border = Border(5.dp, Color.White)) {
            //Row {
            Box(
                modifier = Modifier.fillMaxSize(),
                padding = 10.dp,
                gravity = ContentGravity.CenterStart
            ) { //, padding = 15.dp) {
                //drawClip(shape = RoundedCornerShape(15.dp)) {
                    //Padding(padding = 15.dp) {
                    TextField(
                        //modifier = Modifier.fillMaxSize(),
                        value = state.value,
                        textColor = textColor,
                        keyboardType = keyboardType,
                        imeAction = ImeAction.Done,
                        onValueChange = { state.value = it },
                        onImeActionPerformed = {
                            if (it == ImeAction.Done) {
                                onDone(state.value.text)//   .substring(state.value.selection))
                                hideKeyboard()
                            }
                        },
                        cursorColor = cursorColor,
                        visualTransformation = visualTransformation
                    )
                //}
            }
        }
    }
state.value.text or state.value.text.substring(state.value.selection) don’t just give me the edited string. Grrr…
Copy code
TextFieldValue(text=BIEB, selection=TextRange(start=4, end=4))
TextFieldValue(text=����BIEBER, selection=TextRange(start=8, end=8))
Some new data. The problem only occurs on an older phone using API 24. It looks like Shift keys are stored in the string as 00.