Profeesor, quando eu uso o lazy roow meu app trava, quando nao uso nao trava , sabe me dizer o por que
meu codigo :
package com.example.projetospotyfy.ui.componentes
import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Brush import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil.compose.AsyncImage import com.example.projetospotyfy.Model.Protudo import com.example.projetospotyfy.R import com.example.projetospotyfy.ui.theme.Pink40 import com.example.projetospotyfy.ui.theme.Purple40 import org.jetbrains.annotations.Async import java.math.BigDecimal
@Composable fun proctItem(produtp: Protudo) { // Renomeado para usar minúsculas Surface (Modifier.padding(12.dp), shape = RoundedCornerShape(12.dp), shadowElevation = 4.dp) { Column ( Modifier .heightIn( 250.dp, 300.dp ) .width(200.dp) ) { Box (modifier = Modifier .height(100.dp) .background( brush = Brush.horizontalGradient( colors = listOf( Purple40, Pink40 ) ) ) .fillMaxWidth(), ){ Image( painterResource(id = R.drawable.ic_launcher_background), contentDescription = "Imagem do Produto", Modifier .size(100.dp) .offset(y = (50.dp)) .clip(shape = CircleShape) .align(Alignment.BottomCenter), contentScale = ContentScale.Crop ) } Spacer(modifier = Modifier.height(50.dp)) Text(text = produtp.name, Modifier.padding(start = 16.dp), fontSize = 18.sp, fontWeight = FontWeight(700), maxLines = 2, overflow = TextOverflow.Ellipsis )
Text(text = "R$ ${produtp.preço.toPlainString()}", Modifier.padding(12.dp))
}
}
}
@Preview(name = "Produtos", showBackground = true) @Composable fun ProtudsListPreview() { val produtp = Protudo("rafafafafafafafaf", BigDecimal("14.00"), R.drawable.ic_launcher_background) val produtp1 = Protudo("asfdsddsdsfdsdfsfg", BigDecimal("19.00"), R.drawable.ic_launcher_background) val produtp2 = Protudo("asfdsddsdsfdsdfsfg", BigDecimal("19.00"), R.drawable.ic_launcher_background) val produtp3 = Protudo("asfdsddsdsfdsdfsfg", BigDecimal("19.00"), R.drawable.ic_launcher_background) val produtp4 = Protudo("asfdsddsdsfdsdfsfg", BigDecimal("19.00"), R.drawable.ic_launcher_background) val produtp5 = Protudo("asfdsddsdsfdsdfsfg", BigDecimal("19.00"), R.drawable.ic_launcher_background) var list = listOf(produtp,produtp1,produtp2,produtp3,produtp4,produtp5) Column (Modifier.heightIn()){ Text(text = "Promoções", Modifier.padding(all = 10.dp), fontSize = 12.sp, fontWeight = FontWeight(400), )
LazyRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
items(list) { item ->
proctItem(item)
}
}
}
}