I can use Code A to define a color in Color.kt file which is generated by Android Studio wizard automatically, it's OK.
I hope to define a color based MaterialTheme.colors, but Code B return the following error.
@Composable invocations can only happen from the context of a @Composable function
At present, I have to use Code C, it's not very good, is there a better way?
Code A
val IconColor = Color(0xFF2E7D32)
Code B
val IconColor = MaterialTheme.colors.onSurface.copy(alpha = 0.76f)
Code C
@Composable
fun IconColor(): Color {
return MaterialTheme.colors.onSurface.copy(alpha = 0.76f)
}