Sigh. Sometimes, I think I'm "getting it" and then...
# compose
t
Sigh. Sometimes, I think I'm "getting it" and then... I don't. This code behaves as desired (the list grows as scans are added to the scanList.scans via a "launched flow computation"
Copy code
LazyColumn(modifier = Modifier.weight(1f)) {
	scanList.scans.forEach { result -> 
		item(key = result.device.id) {
			Text(text = "${result.device.name}")
		}
	}
}
But this block, seeming very similar, does not update visually:
Copy code
LazyColumn(modifier = Modifier.weight(1f)) {
   items(items = scanList.scans, key = { result -> result.device.id }) { result ->
      Text(text = "${result.device.name}")
   }
}
I am scratching my head why. Is there some sort of tool, that I can fire up my UI and then see what the dependencies that are going to cause a recomposition are?
m
My guess would be it is related to how scans is added to scanList. Is scans pointing to a MutableCollection that is being updated and assigned to a new instance of scanList? I think that will cause trouble with passing that list to a function like items where it detects that it did not change because the list itself changed so the list in the previous call is equal the list in the new call.
t
Copy code
class ScanList {
   var scans by mutableStateOf<List<ScanResult>>(emptyList())
...
(It was mutableStateList, but changing it was one of the dart throws that didn't work). Either way, it flattens/extracts the value in both cases via scanList.scans. But one works, one does not.
m
I agree that this should work.
s
Both should work from my perspective, please file a bug with complete example 🙂