comparedOf static method
Map<String, List<ChartLabeledData> >
comparedOf(
- List<
ChartLabeledData> oldList, - List<
ChartLabeledData> newList
Implementation
static Map<String, List<ChartLabeledData>> comparedOf(List<ChartLabeledData> oldList, List<ChartLabeledData> newList) {
final oldMap = {for (var item in oldList) item.label: item};
final newMap = {for (var item in newList) item.label: item};
final removed = oldMap.keys.where((label) => !newMap.containsKey(label)).map((label) => oldMap[label]!).toList();
final created = newMap.keys.where((label) => !oldMap.containsKey(label)).map((label) => newMap[label]!).toList();
final changed = newMap.keys
.where((label) => oldMap.containsKey(label) && !((oldMap[label]!) == (newMap[label]!)))
.map((label) => newMap[label]!)
.toList();
return {"removed": removed, "created": created, "changed": changed};
}