apply this to my iplementation: [code]
- User
apply this to my iplementation:
@Composable private fun ValidatedOutlinedTextField( originalValue: String, onValueChange: (String) -> String, modifier: Modifier = Modifier, label: @Composable () -> Unit, validationError: ValidationErrorViewData?, isErrorApplicable: () -> Boolean, keyboardOptions: KeyboardOptions, onSave: (String) -> Unit, onClearError: () -> Unit ) { // Stores the last committed (saved) value as confirmed by the user. // This is used to determine if the input has changed and whether the Save button should be // shown. It also ensures the field reflects the final normalized value after save (e.g., if the // user enters "012", but the system treats and stores it as "12", this becomes the new // committed reference). var committedValue by rememberSaveable { mutableStateOf(originalValue) } var textFieldValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue(committedValue, TextRange(committedValue.length))) } val errorApplicable = isErrorApplicable() val isErrorState = validationError != null && errorApplicable OutlinedTextField( value = textFieldValue, onValueChange = { newValue -> if (isErrorState && newValue.text != textFieldValue.text) { onClearError() } textFieldValue = newValue.copy(text = onValueChange(newValue.text)) }, modifier = modifier, label = label, shape = MaterialTheme.shapes.extraLarge, trailingIcon = { if (textFieldValue.text != committedValue) { SaveButton( onClick = { val finalValue = textFieldValue.text onSave(finalValue) committedValue = finalValue } ) } }, keyboardOptions = keyboardOptions, singleLine = true, isError = isErrorState, supportingText = { if (validationError != null && errorApplicable) { SupportingErrorText(validationError) } else { Spacer(modifier = Modifier.height(16.dp)) } } ) }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.