fillableData

Property

Common
var SemanticsPropertyReceiver.fillableData

The current value of a component that can be autofilled.

This property is used to expose the component's current data to the autofill service. The service can then read this value, for example, to save it for future autofill suggestions.

This is the counterpart to the onFillData action, which is used to receive data from the autofill service.

Code Examples

AutofillableTextFieldWithFillableDataSemantics

@Composable
fun AutofillableTextFieldWithFillableDataSemantics() {
    val state = rememberTextFieldState()
    TextField(
        state = state,
        label = { Text("Enter your username here.") },
        modifier =
            Modifier.semantics {
                contentType = ContentType.Username
                // Set the fillable data with semantics.
                FillableData.createFrom(state.text)?.let { fillableData = it }
                // Replace the state value with data from the autofill provider.
                onFillData { savedAutofillValue ->
                    savedAutofillValue.textValue?.let { state.edit { replace(0, length, it) } }
                    true
                }
            },
    )
}