getting error @Composable invocations can only happen from the context of a @Composable function | composable inside pointerInput

I want to call Text inside detectDragGestures it gives error

error: @Composable invocations can only happen from the context of a @Composable function

Canvas(
        modifier = Modifier
        .fillMaxSize()
        .pointerInput(Unit) {
            detectDragGestures(
                onDragStart = { touch ->
                    Text("0")
                },
                
            )
        }
    )

  • You can’t – onDragStart lambda/closure is not a composable function. However you can use that lambda to mutate a state object, that updates something in that content thats reads the state if you wish.

    – 




  • Do you want to show dragValue to Text or anything else?

    – 

Leave a Comment