Home > Software engineering >  The value 'null' can't be assigned to the parameter type 'Offset' because &
The value 'null' can't be assigned to the parameter type 'Offset' because &

Time:04-16

I've been following a tutorial on youtube for flutter. error comes from "points.add(null)"

enter image description here

CodePudding user response:

In the video you linked, there is a check whether points[x] is null, so I assume the elements of points should be nullable. You can achieve this with

List<Offset?> points = [];

(instead of List<Offset> points = [];). The added questionmark makes it possible for elements of the list to be either a instance of the class Offset or the value null.

CodePudding user response:

The points is non-nullable list.

So this time, it can be solved with to remove points.add(null); inside onPanEnd. (Or add non-null Offset.)

  • Related