Composable Function

rememberTextFieldState

Create and remember a TextFieldState.

rememberTextFieldState

Source set: Common
@Composable
public fun rememberTextFieldState(
    initialText: String = "",
    initialSelection: TextRange = TextRange(initialText.length),
): TextFieldState

Create and remember a TextFieldState. The state is remembered using rememberSaveable and so will be saved and restored with the composition.

If you need to store a TextFieldState in another object, use the TextFieldState.Saver object to manually save and restore the state.

Parameters

initialText The initial text state. If a different value is passed in a subsequent recomposition, the value of the state will not be updated. To update the state after it's initialized, call methods on TextFieldState.
initialSelection The initial selection state. If a different value is passed in a subsequent recomposition, the value of the state will not be updated. To update the state after it's initialized, call methods on TextFieldState.
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: