Created
January 30, 2020 17:56
-
-
Save xsahil03x/c071e4e0578ad0e2acdbe568a8326ae5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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