https://kotlinlang.org logo
Title
p

Pavle Joksovic

01/17/2022, 1:41 PM
I have
private val _toneMap = MutableStateFlow(hashMapOf(0 to listOf<Tone>()))
and I update the value like this
toneMap[index] = tones
val toneMapCopy = HashMap(toneMap)
_toneMap.value = toneMapCopy
there is an issue when the toneMap[index] already contains a list, the value is not updated. Any idea how to fix this?
h

hfhbd

01/17/2022, 6:12 PM
You can't. StateFlow only emits a new value, when you call (emit/setValue) and the new value has a different hashcode. So you should emit a copy instead.
p

Pavle Joksovic

01/18/2022, 7:26 AM
how can I emit a copy?