Why do I get an error when using State<Boolean>
as a parameter? Am I missing an import or package? What am I missing?
@Composable
fun abc(test: State<Boolean>) {
}
Error:
None of the following candidates is applicable:
object State : Any
typealias State = Int
There are multiple types with the name State
available, and you didn't specofy which one you want to use. Therefore the compile error.
The one you most likely want to use, given your context, is probably androidx.compose.runtime.State
. In that case you need to add this to the import section:
import androidx.compose.runtime.State
You can also place the cursor on the error and press Ctrl+Space to see a list of available options.
That should fix the error. However, you shouldn't even have a parameter of type State
in a composable. Only pass the State's value instead:
@Composable
fun abc(test: Boolean) {
}
And finally, Compose functions that have no return value should in general, by convention, start with an upper case letter, i.e.:
@Composable
fun Abc(test: Boolean) {
}
That will get rid of the warning (the yellow squiggly line under abc
in your screenshot) as well.