https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

09/24/2020, 3:34 AM
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

SaurabhS

09/24/2020, 5:06 AM
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

Colton Idle

09/25/2020, 2:08 AM
That worked thank you. And thanks for the explanation.
👍 1