My viemodel:
Class CycleVM{
private val _cycle = MutableStateFlow(Cycle())
override val cycle: StateFlow<Cycle> = _cycle.asStateFlow()
override fun updateImg(imgStr: String) {
val c = cycle.value.copy(cycle.value)
c.image = imgStr
_cycle.value = c
}
override fun updateStartDate(date: Date) {
val c = cycle.value.copy(cycle.value)
c.startDate = date
_cycle.value = c
}
} model:
Class Cycle(
var image: String? = null
) : MyEntity()
{
fun copy(cycle: Cycle): Cycle {....}
}
In my composable I call upfdateDate and date changes everywere, but if I call updateImg() allways the _cycle.value.image == null after line "_cycle.value = c". Call this fun from rememberLauncherForActivityResult.
I can change any variable but not cursed it (image). Why? ;( And if I add another action ( c.id = 20) to the update function, then the image assignment occurs. What hapends? :
override fun updateImg(imgStr: String) {
val c = cycle.value.copy(cycle.value)
c.image = imgStr
c.id = 20 // another action!!!!!!
_cycle.value = c
}
Add logcat