此问题在此处已有答案:
Null check doesn't cause type promotion in Dart(2个答案)
昨天就关门了。
为什么尽管我添加了空值检查,我还是收到这个错误消息?
if (params.page != null) {
++params.page;
}
字符串
错误
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 ('!')
型
3条答案
按热度按时间5lhxktic1#
您可能正在尝试提升一个非私有字段。根据Dart 3.2,只有当字段为私有字段时,字段的类型提升才有效。
请参阅:只能提升私有字段
g9icjywg2#
试试这个
字符串
0kjbasz63#
当然,我可以帮你:
1:if(params.page!= null){ params.page!++ ; //使用非空Assert
}
或本
2:if(params.page!= null){params.page?.++; //使用非null
Assert}