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();
}
}
I've just recheck my code and found an error from where i was getting my latitude and logitude values. Before
currentData.latitude = response["result"]["geometry"]["location.lat"];
currentData.longitude = response["result"]["geometry"]["location.lng"];
After
currentData.latitude = response["result"]["geometry"]["location"]["lat"];
currentData.longitude = response["result"]["geometry"]["location"]["lng"];