I’m trying to create default parameters via leadingIcon: @Composable () -> Unit= {}
or trailingIcon: @Composable (() -> Unit)? = null
, but ran into one problem. An empty form is created on the TextField and for this reason the text is shifted closer to the center.
All the code that I think may affect the display:
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OutlinedTextField(
text: String,
onValueChange: (String) -> Unit,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
leadingIcon: @Composable () -> Unit = {},
trailingIcon: @Composable (() -> Unit)? = null,
// ...
) {
BasicTextField(
value = text,
onValueChange = { onValueChange(it) },
modifier = modifier
.height(68.dp)
.width(OutlinedTextFieldDefaults.MinWidth),
interactionSource = interactionSource,
textStyle = MaterialTheme.typography.bodyMedium.copy(color = colorScheme.onBackground),
// ...
) { innerTextField ->
OutlinedTextFieldDefaults.DecorationBox(
leadingIcon = { leadingIcon() },
trailingIcon = { if (trailingIcon != null) trailingIcon() },
container = {
OutlinedTextFieldDefaults.ContainerBox(
enabled = true,
isError = false,
interactionSource = interactionSource,
colors = colors,
shape = shape
)
}
// ...
)
}
}
Pictures:
What i have
What i want
New contributor
Денис Скурту is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.