first of all sorry for the messed up english, as it is not my first language.
So I’m trying to build a car rental app that uses maps api from google in flutter, I basically have a button to get the current location and after getting that location I want to pop the screen and get the saved data back to the parent screen as seen below
CHILD SCREEN
void savePlace(double lat, double lng) async {
final url = Uri.parse(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=myapikey');
final response = await http.get(url);
final resData = json.decode(response.body);
final address = resData['results'][0]["formatted_address"];
pickedLocation = PickupLocation(
latitude: lat,
longitude: lng,
address: address,
);
isGettingLocation = false;
print("this first");
print(pickedLocation);
if (pickedLocation == null) {
return;
}
}
after executing the code above I pop the pickedLocation data using the navigator pop function from flutter and thus the part where I print "this first" should run before I pop the screen because I put it before the pop screen, however in the parent screen the other code is run first
PARENT SCREEN
void locationData() async {
final selectedLocation = await Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => ParentScreen(),
));
setState(() {
pickedLocation = selectedLocation;
});
print("should be second");
print(pickedLocation);
}
below is the output that is given by the debug console
I/flutter ( 7909): should be second
I/flutter ( 7909): null
I/flutter ( 7909): this first
I/flutter ( 7909): Instance of 'PickupLocation'
the pickedLocation became null because of it ran first instead of waiting for the selectedlocationdata is given
do tell me if you need extra information
2
Answers
I fixed the problem already, I simply run
flutter clean
and rebuild the app and the problem is fixed