Why error detection in Compose doesn't works as ex...
# compose
p
Why error detection in Compose doesn't works as expected? Is there a trick to improve it? For example, in this code:
Copy code
TextField(
    modifier = modifier,
    value = amountInput,
    onValueChange = { amountInput = it },
    singleLine = true,
    label = (Text(stringResource(id = R.string.bill_amount))),
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
)
The detected error is:
Copy code
None of the following functions can be called with the arguments supplied.
TextField(TextFieldValue, (TextFieldValue) → Unit, Modifier = ..., Boolean = ..., Boolean = ..., TextStyle = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., KeyboardActions = ..., Boolean = ..., Int = ..., Int = ..., MutableInteractionSource = ..., Shape = ..., TextFieldColors = ...) defined in androidx.compose.material3
TextField(String, (String) → Unit, Modifier = ..., Boolean = ..., Boolean = ..., TextStyle = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., KeyboardActions = ..., Boolean = ..., Int = ..., Int = ..., MutableInteractionSource = ..., Shape = ..., TextFieldColors = ...) defined in androidx.compose.material3
The error is highlighting in red
TextFieldValue
and
(() → Unit)? = ...
in the error and Android studio is also highlighting in red a portion of the code non related with the error:
it
from onValueChange The real error here is simply that
label = (Text(stringResource(id = R.string.bill_amount)))
must be between
{}
instead of
()
. Why te error detection is not working correctly?
a
Well the error message itself is fine.
label
must be a composable lambda, so of course it should be
{}
. () does nothing.
it
can be known only if the full function matches, right? How else would the IDE know what onValueChange is supposed to be? A single wrong parameter/syntax means nothing matches.
😃 1
p
thank you! for sure these errors must be improved, but now I understand it better