I have created a separate customize component for TextField
in the jetpack component and I import the libraries below, but it's throwing the error like below in the picture
import androidx.compose.material.Text
import androidx.compose.material.TextField
but I couldn't able to compile it, it's throwing the error
my implementation
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
@ExperimentalComposeUiApi
@Composable
fun NoteInputText(
modifier: Modifier = Modifier,
text: String,
label: String,
maxLine: Int = 1,
onTextChange: (String) -> Unit,
onImeAction: () -> Unit = {},
) {
val keyboardController = LocalSoftwareKeyboardController.current
TextField(
value = text,
onValueChange = onTextChange,
colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent
),
maxLine = maxLine,
label = {
Text(text = label)
},
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done,
),
keyboardActions = KeyboardActions(onDone = {
onImeAction()
keyboardController?.hide()
}),
modifier = modifier
)
}
@ExperimentalComposeUiApi
@Preview(showBackground = true)
@Composable
fun Preview() {
NoteInputText(text = "hello", label = "nam", onTextChange = {})
}
that error I'm getting
CodePudding user response:
try maxLine: Int = 1,
to maxLines: Int = 1,
Mistake was in naming, there is no maxLine
in TextField