0

I'm trying to upload files using Dart and I've looked at this previous question to get a feel for what I need to do: How to upload a file in Dart?

However, when I compile I'm getting the following error...

NoSuchMethodError : method not found: 'onChange' 

The following is the code that I used:

import 'dart:html';

void main() {
  InputElement uploadInput = query("#myFile");
  uploadInput.onChange.listen((e) {
    // read file content as dataURL
    final files = uploadInput.files;
    if (files.length == 1) {
      final file = files[0];
      final reader = new FileReader();
      reader.onLoad.listen((e) {
        sendData(reader.result);
      });
      reader.readAsDataUrl(file);
    }
  });
}

void sendData(dynamic data) {
  final req = new HttpRequest();
  req.onreadyStateChange.listen((Event e) {
    if (req.readyState == HttpRequest.DONE &&
        (req.status == 200 || req.status == 0)) {
      window.alert("upload complete");
    }
  });
  req.open("POST", "http://127.0.0.1:8080/upload");
  req.send();
}

Am I missing an import or is Chromium not recognizing the File API?

Community
  • 1
  • 1
jbisa
  • 141
  • 1
  • 2
  • 11

1 Answers1

1

When a variable is null methods invoked on it throw NoSuchMethodError. So uploadInput should be null in your case because onChange exists in the InputElement class .

Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132