0

I have a list of items and other views in the column. I want to set scrollable to the column but I get an error.

My screen code:

 val context = LocalContext.current
        Box(
            modifier = modifier
                .fillMaxSize()
        ) {
            val state = viewModel.state.value
            val scrollState = rememberScrollState()

            Column(modifier = modifier.fillMaxSize().verticalScroll(scrollState)) {
                Spacer(modifier = Modifier.size(24.dp))
                AccountNameSection(modifier = modifier)
                Spacer(modifier = Modifier.size(24.dp))
                if (!state.items.isNullOrEmpty()) {
                    Box(modifier = modifier.fillMaxSize()) {
                        LazyColumn(modifier = modifier.fillMaxSize()) {
                            items(state.items) { item ->
                                ProfileListItems(item = item, onItemClick = {
                                   
                                })
                            }
                        }
                    }
                }

                Text(text = context.getAppVersionName())
            }
            if (state.error.isNotBlank())
                SimpleSnackbar(
                    text = state.error,
                    modifier = modifier.align(Alignment.BottomCenter)
                )

            if (state.isLoading)
                Loading(modifier = modifier.align(Alignment.BottomCenter))

        }

This is the error:

enter image description here

Saeed Noshadi
  • 829
  • 12
  • 34
  • 1
    [Post the error as text](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) – Abhimanyu Oct 29 '21 at 08:48
  • Does this answer your question? [What is the equivalent of \[NestedScrollView + RecyclerView\] or \[Nested RecyclerView (Recycler inside another recycler) in Jetpack compose](https://stackoverflow.com/questions/66908737/what-is-the-equivalent-of-nestedscrollview-recyclerview-or-nested-recyclerv) – Abhimanyu Oct 29 '21 at 08:54
  • I want to scroll all of the components(not only a list) if needed(Device size is small) – Saeed Noshadi Oct 29 '21 at 09:13

2 Answers2

2

You don't apply scrolling to a Column that is a parent to a LazyColumn. Doing so will generate the error that you are seeing. A LazyColumn already has built-in support for scrolling. Remove verticalScroll from your Column. If you need to maintain the state of the scroll position, set the LazyListState property of the LazyColumn.

Johann
  • 27,536
  • 39
  • 165
  • 279
1

You cannot put lazyColumn as child of column without setting specific height according to android documentation.

Use as example:

 LazyColumn(modifier = modifier.width(200.dp)
Kuruchy
  • 1,330
  • 1
  • 14
  • 26
mikelantzelo
  • 182
  • 1
  • 9