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

Sudhir Singh Khanger

03/06/2021, 8:42 AM
I am not able to use
MaterialTheme.colors.onSurface
in a Composable. Cursor hover tells me
org.jetbrains.kotlin.diagnostics.SimpleDiagnostic@9406416a (error: could not render message)
whereas the build window tells me
@Composable invocations can only happen from the context of a @Composable function
But I am using it inside a Composable function.
f

Filip Wiesner

03/06/2021, 9:31 AM
It must be directly inside @Composable function. My guess is that you are using it inside
remember {}
but I can't help you without seeing your code.
2
s

Sudhir Singh Khanger

03/07/2021, 5:28 AM
Copy code
@Composable
fun Test() {
    MyTheme {
        Column {
            Canvas(modifier = Modifier.fillMaxSize()) {
                drawCircle(
                    color = MaterialTheme.colors.onSurface,
                    radius = 10f
                )
            }
        }
    }
}
t

tad

03/08/2021, 2:25 AM
Technically that's in a
DrawScope.()
closure. You need to set a variable before the call to
Canvas
to use it in the closure.
👍 1
s

Sudhir Singh Khanger

03/08/2021, 4:16 AM
Thanks. That worked.
8 Views