canvasdarthtml5-canvasdart-htmldart-webui

Getting Uncaught Error: Invalid argument: null. in Dart


I'm trying to draw a bouncing ball on a canvas created using dart and html bu I keep getting the error Uncaught Error: Invalid argument: null. What do I need to change?

I'm pretty new to dart and I'm using this example to learn

The code is at https://dartpad.dartlang.org/44f020233c9636f43087d235f96b1b4e

I want to make the ball on the canvas to bounce on the canvas being clicked.


Solution

  • The error is really misleading here (you should file a bug) but the issue is because canvas variable is null. In the HTML file the canvas has id surface so you should use:

    canvas = querySelector('#surface');