79463733

Date: 2025-02-24 13:51:47
Score: 0.5
Natty:
Report link

You can create a composable for this grid item to use everywhere without duplicating code:

@Composable
fun GridContentItemWithDivider(
    index: Int,
    columnCount: Int,
    content: @Composable () -> Unit
) {
    val isLastColumn = (index + 1) % columnCount == 0
    Row(Modifier.height(IntrinsicSize.Min)) {
        Column(
            modifier = Modifier.weight(1f),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            content()
            HorizontalDivider()
        }
        if (!isLastColumn) {
            VerticalDivider()
        }
    }
}

and use like this:

val columnCount = 3
LazyVerticalGrid(
    modifier = modifier.fillMaxSize(),
    columns = GridCells.Fixed(columnCount),
) {
    itemsIndexed(uiState.myitems, key = { _, item -> item.id }) { index, item ->
        GridContentItemWithDivider(
            columnCount = columnCount,
            index = index
        ) {
            MyItem(item = item)
        }
    }
}

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: hasan.z