Pablo
03/14/2025, 9:29 AMmapState.mapPois
list, I'm displaying the markers of the map:
@Composable fun MapPanel(mapState: MapState, [...]) {
GoogleMap() {
for (busStop in mapState.busStops) { Marker([...]) }
The parametrized mapstate is collected like this on the parent composable: val mapState by vm.mapState.collectAsStateWithLifecycle()
And is being stored as a state like this on the vm:
data class MapState(val busStops: List<BusStop> = emptyList(),}
[...]
protected val _mapState = MutableStateFlow(MapState())
val mapState: StateFlow<MapState> = _mapState
When mapState.busStop
list is modified on the vm, the map is not being recomposed:
_mapState.update { currentState -> currentState.copy(busStops = favoriteBusStopsList) }
The only way I got the recomposition being triggered is embedding the for that iterates mapState.busStops into a key(mapState.busStops) {
like this:
@Composable fun MapPanel(mapState: MapState, [...]) {
GoogleMap() {
key(mapState.busStops) { for (busStop in mapState.busStops) { Marker([...]) } }
can someone explain me why it's necessary to embed it into key and why recomposition does not trigger if not? Thank you