EDIT
I am still trying to get this to work. I now have and I get an error on the Text
for the label. I am inside a function marked with @Composable. And still have a similar issue with the TextField
too.
@Composable invocations can only happen from the context of a @Composable function
TextField(
value = "Text(text = \"\")",
onValueChange = { },
label = { Text("Label") },// copied from android developer website
Modifier
.padding(0.dp)
.padding(end = dimensionResource(id = R.dimen.child_edge_padding))
)
}
END EDIT
I'm trying to make a login screen for and I'm using TextField
to allow the user to enter an email and password. I cant see anything wrong with what I have but I'm getting an error
None of the following functions can be called with the arguments supplied.
Row(Modifier.padding(dimensionResource(id = R.dimen.container_edge_padding))) {
Text(
text = "${stringResource(id = R.string.email)}} : ",
Modifier
.padding(0.dp) // equivalent to padding inside
.padding(end = dimensionResource(id = R.dimen.child_edge_padding)) // second padding acts as to margin putting space on the inside of the item
)
TextField(
value = "",
placeholder = stringResource(id = R.string.login_email_hint),
Modifier
.padding(0.dp)
.padding(end = dimensionResource(id = R.dimen.child_edge_padding))
)
}
When I hover over it this is what I see.
Using the names of the parameters it shouldnt matter which parameters I use or what position they are relative to the declaration. If I change it like this, because the first 3 parameters are the value, placeholder, modifier it works. But both should work because that is how named parameters works. Providing a default value allows for this. The only way I can get this working is by using the parameters in the order they are declared. Which means if I want to use placeHolder
I have to use the name of every parameter before it, in the order its declared, in order to use it. The only ones that must be declared correctly are value
and onValueChange
because those are the only 2 that dont have a default declared.
TextField(
value = "",
onValueChange = {},
Modifier
.padding(0.dp)
.padding(end = dimensionResource(id = R.dimen.child_edge_padding))
)
I finally got it working by doing this like @Dharmender Manral said
TextField(
value = "",
onValueChange = { },
Modifier
.padding(0.dp)
.padding(start = dimensionResource(id = R.dimen.child_edge_padding)),
enabled = true,
readOnly = false,
textStyle = LocalTextStyle.current,
label = { Text("Label") },
placeholder = { Text(text = stringResource(id = R.string.login_password_hint)) }
)
TextField(
value = "",
onValueChange = { },
Modifier
.padding(0.dp)
.padding(start = dimensionResource(id = R.dimen.child_edge_padding)),
// enabled = true,
// readOnly = false,
// textStyle = LocalTextStyle.current,
label = { Text("Label") },
placeholder = { Text(text = stringResource(id = R.string.login_password_hint)) }
)
So the only difference between what worked and what didnt is as long as the first 3 parameters are in the proper spot and in the correct order the other parameters work as you would expect default parameters to work. Having them in any position. Not sure why it doesnt work with modifier
.