属性“polylinePoints”不能无条件访问,因为接收者可能为“null”
polylines: {
if (_info != null)
Polyline(
polylineId: PolylineId('overview_polyline'),
width: 5,
points: _info.polylinePoints
.map((e) => LatLng(e.latitude, e.longitude))
.toList(),
),
},
我在 _info.polylinPoints 行上遇到错误,但在此之前我确实做了一个条件语句 if (_info != null) 。我知道为什么我仍然收到错误消息吗?
polylines: {
if (_info != null)
Polyline(
polylineId: PolylineId('overview_polyline'),
width: 5,
points: _info.polylinePoints
.map((e) => LatLng(e.latitude, e.longitude))
.toList(),
),
},
I got an error on the line _info.polylinPoints, but i did make a conditional statement prior to this stating if (_info != null) . My I know why I am still getting the error message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使您检查
_info
不为空,该类型稍后也不会自动升级,因为它不是局部变量(我无法通过查看这段代码来确认这一点,但这是一个相当常见的问题)。因此,编译器仍然考虑该变量可能包含可为空值。由于您知道存在 null 检查并且
_info
不会为 null,因此您可以轻松使用 !运算符:在此处。
Even though you check for the
_info
not being null, the type is not automatically promoted later since it's not a local variable (I cannot confirm this by looking at this piece of code, but that's quite a common problem). Thus, the compiler still considers for the variable to possibly hold a nullable value.Since you are aware that the null check is there and
_info
won't be null, you could easily use the ! operator:Check for more information and context here.