Trying to Toast inside of a composable event. How ...
# compose
c
Trying to Toast inside of a composable event. How are you supposed to get a context?
Copy code
TextField(
            value = textState.value,
            onValueChange = { textState.value = it },
            imeAction = ImeAction.Done,
            onImeActionPerformed = { imeAction: ImeAction, softwareKeyboardController: SoftwareKeyboardController? ->
                Toast.makeText(ContextAmbient.current, "asdf", Toast.LENGTH_SHORT).show()
            }
        )
s
The
current
property is a composable and has to be called inside a composable scope.
onImeActionPerformed
is not a composable lambda. Instead, call
val context = ContextAmbient.current
outside the lambda and use that.
👍 2
c
That worked thank you. And thanks for the explanation.
👍 1