Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created January 30, 2020 17:56
Show Gist options
  • Save xsahil03x/c071e4e0578ad0e2acdbe568a8326ae5 to your computer and use it in GitHub Desktop.
Save xsahil03x/c071e4e0578ad0e2acdbe568a8326ae5 to your computer and use it in GitHub Desktop.
import 'dart:collection';
import 'dart:convert';
void main() {
final data = json.decode(
"[{\"videoId\":1,\"videoName\":\"Test Video 1\",\"duration\":300,\"createdTime\":\"1969-07-20 20:18:04Z\",\"isWatch\":1},{\"videoId\":1,\"videoName\":\"Test Video 1\",\"duration\":300,\"createdTime\":\"1969-07-20 20:18:04Z\",\"isWatch\":50},{\"videoId\":1,\"videoName\":\"Test Video 1\",\"duration\":300,\"createdTime\":\"1969-07-21 20:18:04Z\",\"isWatch\":20}]");
final map = HashMap<String, int>();
for (var value in (data as List)) {
if (map[value['createdTime']] == null) {
map[value['createdTime']] = value['isWatch'];
} else {
map[value['createdTime']] = map[value['createdTime']] + value['isWatch'];
}
}
print(map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment