【发布时间】:2021-08-10 02:49:00
【问题描述】:
我只是将我的项目转换为 Null Safety,但我收到错误提示
The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!').
我有点困惑,我不知道该怎么办。
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data['Interest'].length ,// i am getting error here
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 12.0),
child: bottomCardList(
'assets/1 (6).jpeg',
snapshot.data['Interest'][index]// i am getting error here
.toString(),
() {}),
);
});
}),
谢谢
【问题讨论】:
-
snapshot.data['Interest'] 可以为空,所以也许你可以这样检查:snapshot.data['Interest'] != null ? snapshot.data['Interest'].length : 0
-
@JorgeVieira 仍然给了我错误
标签: flutter dart dart-null-safety