错误:flutter/lib/ui/ui_dart_state.cc(198)]未经手的例外:null检查运算符在空值上使用
大家好,我将面临问题(null检查操作员在null值上使用)时,当我删除此操作员时,它给我错误的是我的代码
Future<void> getDirectionDetails() async {
var pickUpDetails =
Provider.of<AppData>(context, listen: false).currentPickupAddress;
var destinationDetails =
Provider.of<AppData>(context, listen: false).destinationAddress;
var pickUpLatLang =
LatLng(pickUpDetails!.latitude!, pickUpDetails.longitude!);
var destinationLatLang =
LatLng(destinationDetails!.latitude!, destinationDetails.longitude!);
showDialog(
context: context,
builder: (BuildContext context) =>
ProgressDialog(status: "Please Wait"));
var locationDetails = await GeocodeHelper.getDirectionDetails(
pickUpLatLang, destinationLatLang);
print(locationDetails.EncodingPoints);
Navigator.pop(context);
}
,这是我的班级。信息。
class AppData extends ChangeNotifier {
Address? currentPickupAddress;
Address? destinationAddress;
void updatePickupAddress(Address pickup) {
currentPickupAddress = pickup;
notifyListeners();
}
void updateDestinationAddress(Address destination) {
destinationAddress = destination;
notifyListeners();
}
}
Hi Everyone i am facing an issue (null check operator used on null value) when i remove this operator it gives me Error here is my code
Future<void> getDirectionDetails() async {
var pickUpDetails =
Provider.of<AppData>(context, listen: false).currentPickupAddress;
var destinationDetails =
Provider.of<AppData>(context, listen: false).destinationAddress;
var pickUpLatLang =
LatLng(pickUpDetails!.latitude!, pickUpDetails.longitude!);
var destinationLatLang =
LatLng(destinationDetails!.latitude!, destinationDetails.longitude!);
showDialog(
context: context,
builder: (BuildContext context) =>
ProgressDialog(status: "Please Wait"));
var locationDetails = await GeocodeHelper.getDirectionDetails(
pickUpLatLang, destinationLatLang);
print(locationDetails.EncodingPoints);
Navigator.pop(context);
}
And this is my Class from where i am getting this information.
class AppData extends ChangeNotifier {
Address? currentPickupAddress;
Address? destinationAddress;
void updatePickupAddress(Address pickup) {
currentPickupAddress = pickup;
notifyListeners();
}
void updateDestinationAddress(Address destination) {
destinationAddress = destination;
notifyListeners();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想问题是在这个代码块中
看到您正在强迫拾音器,纬度和经度,而无需检查值是否为null,这给出了问题。
当然,您可以尝试以下内容,
我假设纬度和经度是INT类型,如果不是,请提供合适的默认值。
I guess the problem is in this block of code
See you are force unwrapping the pickUpDetails,latitude and longitude without checking if there value is null or not which gives the issue.
you can try the following
Of course I'm assuming that latitude and longitude are of type int, if not please provide the suitable default value.
我只是重新检查我的代码,并从获得纬度和逻辑值的位置找到了一个错误。
之后
I've just recheck my code and found an error from where i was getting my latitude and logitude values.
Before
After