TextFieldStateAdapter
An adapter interface specifically designed for TextFieldState type conversion.
This specialized adapter works with Compose's TextFieldState, maintaining the state object for input/display while allowing conversion to a different type for validation. The stored value and input types are always TextFieldState, but the validation target type can be customized.
This is particularly useful when you need to validate the text content as a specific type (e.g., numbers, dates, emails) while keeping the TextFieldState for UI interaction.
Usage:
class IntTextFieldStateAdapter : TextFieldStateAdapter<Int?> {
override fun toValidationTarget(value: TextFieldState): Int? {
return value.text.toString().toIntOrNull()
}
}
Content copied to clipboard
Parameters
S
The type used for validation (e.g., Int, Date, or custom types).