I created a LazyColumn that is getting the items from the viewModel and every thing is working perfectly, But What I want is when a new Item is inserted to the lazy column I want the the background color of the new Item to be green for 2 seconds and then it turns back to white . And here is what I did to achieve that but the Item keeps being green:
@Composable
fun SingleItem(item: Item) {
val new = remember {
mutableStateOf(true)
}
val color: MutableState<Color> = remember {
if (new.value)
mutableStateOf(Color(0xFFB9F6CA))
else
mutableStateOf(Color(0xFFFDFDFD))
}
Card(
modifier = Modifier
.padding(4.dp)
.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
backgroundColor = color.value
) {
GlobalScope.launch {
delay(2000)
new.value= !new.value
}
Column(
modifier = Modifier
.fillMaxWidth(),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.SpaceBetween
) {
Text(text = item.name, style = MaterialTheme.typography.h5)
Text(text = "${item.quantity}", style = MaterialTheme.typography.h6)
}
}