Hey guys. Can someone know how to update list in M...
# android
v
Hey guys. Can someone know how to update list in MutableStateFlow . When I am adding more value, my previous value will drop. Please someone guide me
z
Looks like you’re creating an empty list, populating it with the date range query results, then updating the state value. If the date range is different, and that produces a different date range query result, wouldn’t that be the expected behavior?
v
@Zach Klippenstein (he/him) [MOD] I want to append the new data in the current/existing result every time, when new date range is different
z
so you want
Copy code
prepareMutableStateFlow.value += conversationCount
instead of
Copy code
prepareMutableStateFlow.value = conversationCount
?
or alternatively,
Copy code
val conversationCount = prepareMutableStateFlow.value.toMutableList()
…
prepareMutableStateFlow.value = conversationCount
v
Which way do you prefer @Zach Klippenstein (he/him) [MOD]?
I am learning this mutableStateFlow so i don't know
z
this isn’t a mutable state flow issue, the same thing would apply if it were just a regular
var
i don’t really have a strong preference either way, the point is that if you want to append to the list, you need to append to the list 😉
v
@Zach Klippenstein (he/him) [MOD] one thing after using this
prepareMutableStateFlow.value = conversationCount + prepareMutableStateFlow.value
my recylerview jumps scroll to few page
g
It’s not directly related on shared flow, but rather on how you recycler view is implemented, you can check for example Paging library or DiffUtils for recycler view