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

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


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');

Answered By – Alexandre Ardhuin

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *