Thread
#compose
    a

    Arun

    1 year ago
    Hello! I want square
    Box
    items. Let’s say I have the following. How do I make sure the
    Box
    child composables are perfect squares? What value do I have to set it’s
    height
    to?
    @Composable
    @Preview
    fun PreviewSquareItems() {
    
        Row(modifier = Modifier.fillMaxWidth()) {
            val total = 2
    
            repeat(total) { index ->
    
                Box(
                    modifier = Modifier
                        .weight(1f)
                        .height(245.dp) // how to find this height?
                        .clip(RoundedCornerShape(8.dp))
                        .background(color = Color.Blue),
                )
    
                if (index + 1 < total) {
                    Spacer(modifier = Modifier.width(10.dp))
                }
            }
        }
    }
    s

    Se7eN

    1 year ago
    Try
    Modifier.aspectRatio(1f)