I am trying to create a dropdown with multiple selection in android jetpack.
This is the UI which needs to be created and also the code snippet.
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.fillMaxHeight()
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
Surface(
color = Color.White
) {
LazyVerticalGrid(
state = rememberLazyGridState(),
modifier = Modifier.fillMaxSize(),
columns = GridCells.Fixed(2)
) {
itemsIndexed(items = list) { index, item ->
ListItemView_New(text = item, model = list[index], position = index)
}
}
}
}
@Composable
fun ListItemView_New(model: String, position: Int, text: String) {
Box(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(vertical = 6.dp, horizontal = 16.dp)
) {
Checkbox(
checked = false, onCheckedChange = {
},
colors = CheckboxDefaults.colors(
checkedColor = Color.Black,
uncheckedColor = Color.Gray
),
modifier = Modifier
.align(Alignment.CenterStart)
)
Text(
text = text,
fontSize = 18.sp,
color = Color.Gray,
fontWeight = FontWeight.Normal,
modifier = Modifier
.align(Alignment.CenterStart)
.padding(start = 48.dp)
)
}
}
it gives the following error
Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
I think, it gives the error as there is:
.verticalScroll(rememberScrollState()) and LazyVerticalGrid
in the same compose.
but I am not able to find a work around. Can someone please help here.