@@ -57,7 +57,7 @@ class LocationInfoImpl implements LocationInfo {
5757 final loc = _deviceLocation.value;
5858 if (loc == null ) {
5959 throw LocationException (
60- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
60+ '${Constants .locationNotAvailable }' ,
6161 );
6262 }
6363 return loc;
@@ -73,7 +73,7 @@ class LocationInfoImpl implements LocationInfo {
7373 /// This is done because iOS app gets rejected if we ask for location
7474 /// on splash and if it is disabled, user is asked to turn on the location
7575 /// to use the app
76- if (! Platform .isIOS){
76+ if (! Platform .isIOS) {
7777 final permissionStatus = await isLocationPermissionGranted ();
7878
7979 if (! permissionStatus) {
@@ -88,23 +88,27 @@ class LocationInfoImpl implements LocationInfo {
8888 }
8989
9090 final permission = await Geolocator .requestPermission ();
91+
9192 final geolocationStatus = await Geolocator .isLocationServiceEnabled ();
93+ if (! geolocationStatus) {
94+ throw LocationException ('Oops! Location is turned off' );
95+ }
96+ if (! _isPermissionGranted (permission)) {
97+ throw LocationException ('Please Allow Location Permission' );
98+ }
9299
93- if (_isPermissionGranted (permission) && geolocationStatus) {
94- await _fetchLocation ();
95- } else if (! geolocationStatus) {
100+ final accuracy = await Geolocator .getLocationAccuracy ();
101+ if (accuracy == LocationAccuracyStatus .reduced) {
96102 throw LocationException (
97- 'Location setting on your device is off.'
98- ' Please enable to proceed!\n $defaultLocationReason ' ,
99- );
100- } else if (! _isPermissionGranted (permission)) {
101- throw LocationException (
102- 'Please enable Location Permission to the App!'
103- '\n $defaultLocationReason ' ,
103+ 'Please Enable Precise Location' ,
104104 );
105+ }
106+
107+ if (_isPermissionGranted (permission) && geolocationStatus) {
108+ await _fetchLocation ();
105109 } else {
106110 throw LocationException (
107- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
111+ '${Constants .locationNotAvailable }' ,
108112 );
109113 }
110114 } else {
@@ -184,7 +188,7 @@ class LocationInfoImpl implements LocationInfo {
184188 //prefsHelper.lastLocation = jsonEncode(_deviceLocation.value.toJson());
185189 } else {
186190 throw LocationException (
187- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
191+ '${Constants .locationNotAvailable }' ,
188192 );
189193 }
190194 }
@@ -224,7 +228,7 @@ class LocationInfoImpl implements LocationInfo {
224228 });
225229 if (position == null ) {
226230 throw LocationException (
227- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
231+ '${Constants .locationNotAvailable }' ,
228232 );
229233 } else {
230234 await _onLocationFetch (position);
@@ -248,7 +252,7 @@ class LocationInfoImpl implements LocationInfo {
248252 location = await _getLocation ();
249253 if (location == null ) {
250254 throw LocationException (
251- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
255+ '${Constants .locationNotAvailable }' ,
252256 );
253257 }
254258 await _onLocationFetch (location);
@@ -258,7 +262,7 @@ class LocationInfoImpl implements LocationInfo {
258262 final isTimerActive = locationCheckTimer? .isActive ?? false ;
259263 if (! isTimerActive) {
260264 locationCheckTimer =
261- Timer .periodic (const Duration (seconds: 4 ), (t) async {
265+ Timer .periodic (const Duration (seconds: 1 ), (t) async {
262266 final _checkPermission = await isLocationPermissionGranted ();
263267 final geolocationStatus = await isLocationEnabled ();
264268 if (! _checkPermission || ! geolocationStatus) {
@@ -269,10 +273,16 @@ class LocationInfoImpl implements LocationInfo {
269273 builder: (_) => AppErrorPage (
270274 LocationException (
271275 '${Constants .locationNotAvailable }'
272- ' \n $ defaultLocationReason ' ,
276+ ' ' ,
273277 ),
274278 onRetryTap: () async {
275- await initLocation ();
279+ final _checkPermission = await isLocationPermissionGranted ();
280+ final geolocationStatus = await isLocationEnabled ();
281+ if (_checkPermission && geolocationStatus) {
282+ navKey! .currentState? .pop ();
283+ _startLocationServiceCheckTimer ();
284+ await initLocation ();
285+ }
276286 },
277287 ),
278288 ),
@@ -313,7 +323,7 @@ class LocationInfoImpl implements LocationInfo {
313323 /// TODO(@singhtaranjeet): Do not throw only LocationException on every exception
314324 /// Use different exception for different cases
315325 throw LocationException (
316- '${Constants .locationNotAvailable }\n $ defaultLocationReason ' ,
326+ '${Constants .locationNotAvailable }' ,
317327 );
318328 }
319329 }
0 commit comments