在 Dart 中获取 NoSuchMethodError

Dav*_*ood 5 nosuchmethoderror dart

我对 Dart 很陌生,我习惯于使用 C#(通常还有 XNA),所以 Dart 有点不同,我不确定为什么会发生这个错误。

double left = c.Position.x - (canvasDimensions.x * 0.5);
Run Code Online (Sandbox Code Playgroud)

Position 和 canvasDimensions 是我创建的一种类型,称为 Vector2,它基本上包含 2 个数字,x 和 y,我收到错误

NoSuchMethodError : method not found: '-'
Receiver: null
Arguments: [600.0]
Run Code Online (Sandbox Code Playgroud)

在显示的行中,由于我不熟悉该语言,我不确定为什么会发生这种情况,请帮助,谢谢!

Ale*_*uin 3

c.Position.xnull。在 Dart 中,调用方法(或-您的情况下的运算符)null会导致NoSuchMethodError.