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()
}
}

Parameters

S

The type used for validation (e.g., Int, Date, or custom types).

Inheritors

Functions

Link copied to clipboard
open override fun fromInput(value: TextFieldState, current: TextFieldState): TextFieldState

Converts the input/display value back to the stored value type.

Link copied to clipboard
open override fun toInput(value: TextFieldState): TextFieldState

Converts the stored value to the input/display type.

Link copied to clipboard
abstract fun toValidationTarget(value: TextFieldState): S

Converts the stored value to the validation target type.