I am following Angela Yu Bootcamp for flutter I have came across clima weather app project using geo locator for location and openweathermap Api. All my code works fine in android emulator but after building apk in real android device or mobile it is not navigating automatically to location page or next page after accepting permission for location Just stays in same page
@override
initState() {
// ! here get all properties of parent init when stateful widget build
super.initState();
// !adds additional properties
getLongLatCoOrd();
}
Future<void> getLongLatCoOrd() async {
// !class obj created for locaion service also checked permision and request
MyLocationService gettingGpsLoc = MyLocationService();
// !waiting future function response for coordinates
await gettingGpsLoc.getCurrentLocationService();
latitude = gettingGpsLoc.currentLatitude;
longitude = gettingGpsLoc.currentLongitude;
// !class obj for data services
NetworkHelper netHelperFordata = NetworkHelper(
url: '$apiUrl?lat=$latitude&lon=$longitude&appid=$apiKey');
// !wait for data to complete
dynamic weatherData = await netHelperFordata.getDataFromAPi();
if (!mounted) return;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LocationScreen(
recievedApiData: weatherData!,
);
},
),
);
this function works completely fine in Android Emulator and web
I wanted to get location using latest geolocator package and also used permission from android manifest then with the received co-ordinates I fetched API response and I am getting the data and I am navigating to next page by passing the received API response to LocationScreen worked completely fine in emulator but it is not working with apk installation in real device.
Note: used device permission according to documentation for geolocator in directory android>app>src>main>androidmanifest.xml file
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LocationScreen(
recievedApiData: weatherData!,
);
},
),
);
when installed in real device it is stucked in same page after location permission it is not moving to next page or navigating to next page with recieved Api data .