Issue
I can have
val composeFunction = remember { mutableStateOf ({}) }
I can have
val composeFF = @Composable { Text("ABC") }
val composeFunction = remember { mutableStateOf (composeFF) }
val composeFunction = remember { mutableStateOf (@Composable { Text("ABC") }) }
It errors out state
Internal Error occurred while analyzing this expression
(Please use the "
" icon in the bottom-right corner to report this error):
jar:file:/Applications/Android%20Studio.app/Contents/lib/platform-impl.jar!/general/error.svg
Type inference failed. Expected type mismatch: inferred type is @Composable () -> Unit but () -> Unit was expected
Solution
Have you tried specifying the type?
val composeFunction = remember { mutableStateOf<@Composable () -> Unit> (@Composable { Text("ABC") }) }
Looks like the compiler cannot infer an ordinary function to something that is supplied with a @Composable
annotation
Answered By - z.y
Answer Checked By - Terry (JavaFixing Volunteer)