toastEffect

fun toastEffect(duration: Int = Toast.LENGTH_SHORT): (String) -> Unit(source)

A composable function that returns a lambda to show a Toast. Any previously shown toast will be cancelled when a new one is shown or this composable exits composition. The returned lambda can be called with the text to show in the toast.

val showToast = toastEffect()
// ...
Button(onClick = { showToast("Hello, world!") }) {
Text("Show Toast")
}

Parameters

duration

The duration of the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.