Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. void uploadFile() async {
  2.  
  3. submitButton.attributes.addAll({'disabled': ''});
  4. progress.value = 0;
  5.  
  6. FileList files = input.files;
  7.  
  8. if(files.isEmpty){
  9. _handleError("No file selected");
  10. //handle error, probably a banner
  11. return;
  12. }
  13.  
  14. File file = files.item(0);
  15.  
  16. FileReader reader = new FileReader();
  17. //reader.result
  18. reader.onLoadEnd.listen((e) async {
  19.  
  20.  
  21. Map map = json.decode(reader.result);
  22.  
  23. var combinations = map['combinations'];
  24.  
  25. progress.max = combinations.length;
  26.  
  27. int loopCount = 0;
  28.  
  29. combinations.forEach((e) async {
  30. await _service.create(VJCombination.fromJSON(e)).then((_) {
  31. combinationCount++;
  32. progress.value ++;
  33.  
  34. loopCount++;
  35.  
  36. if(loopCount == combinations.length){
  37. submitButton.attributes.remove('disabled');
  38. }
  39. });
  40.  
  41. });
  42.  
  43. isLoadSuccessful = true;
  44.  
  45. });
  46.  
  47. reader.onError.listen((evt) => print(evt));
  48.  
  49. reader.readAsText(file);
  50.  
  51. progress.value = 10;
  52.  
  53. }
  54.  
  55. @ViewChild('progress')
  56. ProgressElement progress;
  57.  
  58. @ViewChild('submit')
  59. ButtonElement submitButton;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement