Really confusing error: type 'Screen' is n

2019-07-16 01:29发布

问题:

Hi I am writing a Dart app and I am getting the error:

type 'Screen' is not a subtype of type 'Screen' of 'function result'.

I have literally no idea what the actual error is?

My code is as follows:

class CanvasManager {
  Map<String, Screen> _canvases = new Map<String, Screen>();
  CanvasManager (Map<String, CanvasElement> reqCanvas, int sizeX, int sizeY, bool fullscreen) {
    reqCanvas.forEach((k,v) {
      _canvases[k] = new Screen.create(v, sizeX, sizeY, fullscreen);
    });
  }
  Screen getCanvas(String c) {
    if (_canvases.containsKey(c)) {
    return _canvases[c];
    }
    else throw "No such canvas with key ${c}";
  }
}

For some reason when I instance that class I get the error.

Just to note Screen is a class I have also created. As I'm completely baffeled I don't know if it will help you by giving you that class as well. It's somewhat long so I will paste-bin it: http://pastebin.com/KvZ54yPe

回答1:

Fixed it!

Screen is already a class name in dart:html. The compiler really should tell you if you have reused a class name with some sort of warning but it doesn't.



标签: dart