Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LazyColumn inside vertically scrollable Column

I have a Column(modifier = Modifier.verticalScroll(mainScrollState)) and I want to use LazyColumn inside Column WITHOUT specifying height of LazyColumn explicitly.

Now it gives me java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed.

I tried using NestedScrollConnection but it didn't give me right solution. Any workarounds?

My whole composable looks like:

Scaffold() {
    Column() {
       Column() { 
          LazyColumn { ... }
       }
       Column() { ... }
    }
}
like image 795
Sosiskin Avatar asked May 30 '26 17:05

Sosiskin


1 Answers

I use this workaround

Column(
    modifier = Modifier
        .fillMaxWidth()
        .verticalScroll(rememberScrollState())
) {
    LazyColumn(
        modifier = Modifier.heightIn(2000.dp) // set the maximum height possible in your case
    ) {
        // your content
    }
}

You may use heightIn(), so compose will know the exact height of element. This works like wrapContentHeight, but there is a maximum height allowed

I think it's more suitable for small number of items, though

like image 172
Ivan Avatar answered Jun 01 '26 08:06

Ivan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!