when I create a mutableStateOf (true) in foreach to hide a Row and click on the first item removes all options I wanted to remove just the row that has the button inside
I tried to create a MutableState array val visible = arrayOf <MutableState<Boolean>> () but it gives error what is the best way to do this within the foreach
How can I fix this error
My Code:
@Composable
private fun Content(){
Column(modifier=Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Top){
//val visibles= arrayOf<MutableState<Boolean>>()
if(i.isNotEmpty()){
i.forEachIndexed { index, item ->
var quantidades by remember{ mutableStateOf(TextFieldValue(item.quantidade.toString())) }
var visible by remember {
mutableStateOf(true)
}
if(visible) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(bottom = 8.dp)
.fillMaxWidth(100f)
) {
CoilImage(
data = item.photo,
contentDescription = item.name,
fadeIn = true,
loading = {
Box(Modifier.fillMaxSize()) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
}
},
modifier = Modifier
.size(100.dp),
error = {
Image(
painterResource(R.drawable.ic_launcher_background),
contentDescription = "Error"
)
}
)
Text(
text = item.name,
fontSize = 15.sp,
modifier = Modifier.padding(end = 20.dp)
)
// Text(text=item.count.toString())
// Text(text=item.id.toString())
TextField(
value = quantidades,
onValueChange = {
quantidades = it
//_addUserState.value = _addUserState.value?.copy(name = it)
},
shape = RoundedCornerShape(8.dp),
colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent
),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
),
modifier = Modifier
.width(50.dp)
.height(50.dp)
)
Column(
modifier = Modifier
.fillMaxWidth(100f)
.padding(5.dp), horizontalAlignment = Alignment.End
) {
Button(
onClick = { visible=onVisible(visible,item) },
modifier = Modifier.padding(end = 20.dp)
) {
Icon(
Icons.Default.Delete,
stringResource(id = R.string.deletar)
)
}
}
}
}
}
}else{
Text(text= stringResource(id = R.string.sem_carrinho), fontSize = 15.sp)
}
}
}
private fun onVisible(visible: Boolean, item:ShoppingCart):Boolean{
counter.value--
i.remove(item)
return !visible
}