Tengo puesta la lista como mutableList y rememberSaveable, elimino la hora que quiero pero no se me actualiza la pantalla, por lo que la hora no se elimina de la pantalla
codigo Abajo
En el viewModel solo hay un String con la fecha
Codigo
import android.util.Log
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowForward
import androidx.compose.material.icons.filled.Build
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import com.diasApp.myapplication.ui.util.createFile
import com.diasApp.myapplication.ui.util.deleteFile
import com.diasApp.myapplication.ui.util.readFile
import com.diasApp.myapplication.viewModel.DiasViewModel
@Composable
fun DayScreen(diasViewModel: DiasViewModel){
val context = LocalContext.current
var horasString = readFile(context, diasViewModel.fechaActual)
var horas by rememberSaveable {
mutableStateOf(horasString.trim().split("\n").toMutableList())
}
LazyColumn() {
items(horas) { hora ->
cardsHora(hora, onBorrar = { horaEliminar ->
horas.remove(horaEliminar)
})
}
}
}
@Composable
fun cardsHora(hora: String, onBorrar: (String) -> Unit) {
Card {
Row {
TextButton(onClick = {
onBorrar(hora)
Log.d("HORAS", "hora : ${hora}")
}) {
Text(text = hora)
}
ComprobarDiaoNoche(hora)
}
}
}
@Composable
fun ComprobarDiaoNoche(hora: String) {
val horaTemporal = hora.substring(0,2).toInt()
if (horaTemporal > 8 && horaTemporal < 19){
Icon(
imageVector = Icons.Default.Build,
contentDescription = "Sol"
)
} else {
Icon(
imageVector = Icons.Default.ArrowForward,
contentDescription = "Luna"
)
}
}
MutableStateFlow
.