“@Composable invocations can only happen from the context of a @Composable function“
I’m new to jetpack compose and constantly getting this error “@Composable invocations can only happen from the context of a @Composable function” on adding icon and label in the Text Field.
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EditNumberField(
value: String,
@StringRes label: Int,
@DrawableRes icon: Int,
keyboardOptions: KeyboardOptions,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier
){
TextField(
value = value,
label = { Text(stringResource(label)) },
icon = { Icon(painter = painterResource(id = icon), contentDescription = null) },
keyboardOptions = keyboardOptions,
onValueChange = onValueChange,
singleLine = true,
modifier = modifier,
colors = TextFieldDefaults.textFieldColors(
containerColor = Color(0xFFBDFCC9))
)
}
“TextField(), label = {Text()}, icon = {Icon()}” these lines are underlined by red showing the error mentioned above.
New contributor
user25472147 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.