In this code, in the text parameter, I get the error: @Composable invocations can only happen from the context of a @Composable function, the same happens to me with icon: @Composable invocations can only happen from the context of a @Composable function
If I delete the text parameter and the icon parameter, the code works correctly, but I want to display a text and an icon in each tab. I have imported androidx.compose.material3.Tab and the dependency implementation(platform(“androidx.compose:compose-bom:2024.04.01”)), I don’t know what else to try
PrimaryTabRow(
selectedTabIndex = selectedTabIndex
) {
tabItems.forEachIndexed { index, item ->
Tab(
selected = (selectedTabIndex == index),
onClick = {
selectedTabIndex = index
},
text = { Text(text = item.titulo)},
icon = {
Icon(
imageVector = if (index == selectedTabIndex) item.selecIcon else item.unselecIcon,
contentDescription = item.titulo
)
}
) {
}
}
}
Ziki Rach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.