> Documentation index: https://developer.android.com/reference/llms.txt

# TextFieldState.Saver

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+class:androidx.compose.foundation.text.input.TextFieldState.Saver) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt#1.7.0) Common/All
- Cmn

  ```
  object TextFieldState.Saver : Saver<TextFieldState, Any>
  ```

*** ** * ** ***

Saves and restores a `TextFieldState` for `rememberSaveable`.

A restored state has no `onTextChanged` callback. To restore a state that was created with `onTextChanged`, use the `Saver` returned by `TextFieldState.Saver(onTextChanged)`.

| See also |
|---|---|
| `rememberTextFieldState` |   |

## Summary

| ### Public functions |
|---|---|---|
| `operator Saver<TextFieldState, Any>` | `invoke(onTextChanged: ((CharSequence) -> Unit)?)` Returns a `Saver` that saves a `TextFieldState` the same way as `Saver` and passes `onTextChanged` to the restored state. | Cmn |
| `open TextFieldState?` | `restore(value: Any)` Convert the restored value back to the original Class. | Cmn |
| `open Any?` | `SaverScope.save(value: TextFieldState)` Convert the value into a saveable one. | Cmn |

## Public functions

### invoke

Cmn Added in [1.14.0-alpha01](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt#1.14.0-alpha01)

```
operator fun invoke(onTextChanged: ((CharSequence) -> Unit)?): Saver<TextFieldState, Any>
```

Returns a `Saver` that saves a `TextFieldState` the same way as `Saver` and passes `onTextChanged` to the restored state.

A lambda cannot be saved, so a state restored by `Saver` has no `onTextChanged`. Use this function to save a state that was created with `onTextChanged`, for example with `rememberSaveable(saver = TextFieldState.Saver(onTextChanged))`. `rememberTextFieldState` does this.

`onTextChanged` is called after each commit that changes the text of the restored state: user input, `TextFieldState.edit` and its helpers, and undo/redo. It is not called when only the selection, composition, or styles change. `onTextChanged` runs on the thread that made the edit, before the edit call returns. When `onTextChanged` runs, `TextFieldState.text` and `TextFieldState.selection` show the new value, the undo entry is recorded, and the IME has been notified.

`onTextChanged` must not change the state. Calling `TextFieldState.edit`, its helpers, or `UndoState.undo` and `UndoState.redo` on the state from `onTextChanged` throws an `IllegalStateException`. To intercept and modify user input, use `InputTransformation`.

The `CharSequence` passed to `onTextChanged` is provided for convenience and has the same text content as `TextFieldState.text`.

| Parameters |
|---|---|
| `onTextChanged: ((CharSequence) -> Unit)?` | Called after each commit that changes the text of the restored state, receiving the new text with the same content as `TextFieldState.text`. |

### restore

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt#1.7.0)

```
open fun restore(value: Any): TextFieldState?
```

Convert the restored value back to the original Class. If null is returned the value will not be restored and would be initialized again instead.

### SaverScope.save

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/input/TextFieldState.kt+function:save) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation.md.txt#1.7.0)

```
open fun SaverScope.save(value: TextFieldState): Any?
```

Convert the value into a saveable one. If null is returned the value will not be saved.