Skip to content

Commit f1ef088

Browse files
kapdroidKapdroid
authored andcommitted
refactor(location): location logging message (#169)
Signed-off-by: Kapdroid <kapdroid@Kapdroids-MacBook-Pro.local> Co-authored-by: Kapdroid <kapdroid@Kapdroids-MacBook-Pro.local>
1 parent 907681c commit f1ef088

6 files changed

Lines changed: 395 additions & 89 deletions

File tree

lib/src/app/app_error_page.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ class AppErrorPage extends StatelessWidget {
55
const AppErrorPage(
66
this.e, {
77
this.onRetryTap,
8+
this.hasSettingButton = false,
89
});
910

1011
final dynamic e;
1112
final VoidCallback? onRetryTap;
13+
final bool hasSettingButton;
1214

1315
@override
1416
Widget build(BuildContext context) {
1517
return MaterialApp(
1618
debugShowCheckedModeBanner: false,
17-
home: Scaffold(
18-
body: Center(
19-
child: Column(
19+
home: SafeArea(
20+
child: BaseScaffold(
21+
appBody: Column(
2022
mainAxisSize: MainAxisSize.min,
2123
children: [
2224
getWidget(),
@@ -32,15 +34,18 @@ class AppErrorPage extends StatelessWidget {
3234
// if (e is LocationException) {
3335
if (e is LocationException) {
3436
return LocationErrorWidget(
37+
hasSettingButton: hasSettingButton,
3538
error: e.toString(),
3639
onRefreshTap: onRetryTap ?? () {},
3740
pop: false,
3841
);
3942
} else {
40-
return UnknownErrorWidget(
41-
onRetryTap ?? () {},
42-
pop: false,
43-
message: e?.toString() ?? Constants.errorSomethingWentWrong,
43+
return Center(
44+
child: UnknownErrorWidget(
45+
onRetryTap ?? () {},
46+
pop: false,
47+
message: e?.toString() ?? Constants.errorSomethingWentWrong,
48+
),
4449
);
4550
}
4651
}

lib/src/config/colors.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class AppColors {
2121

2222
static Color kCustomDarkBlue = Color(0xFF005486);
2323

24+
static Color kDarkBlue = Color(0xFF072A72);
25+
2426
static Color kOutlinedIconButtonBackgroundColor = Color(0xffFAFAFA);
2527

2628
static Color kOutlinedIconButtonBorderColor = Color(0xffDCDCDC);
@@ -35,4 +37,6 @@ class AppColors {
3537
},
3638
);
3739
static const Color kLightGrey = Color(0xFF666666);
40+
41+
static const Color kLightBlue = Color(0xFFEDF6FF);
3842
}

lib/src/constants/constants.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ class Constants {
33

44
static const String errorSomethingWentWrong = "Oops! Something went wrong.";
55

6-
static const String locationNotAvailable =
7-
"Location not available!\n\nPlease try following things:\n\n-"
8-
" Check location is on"
9-
" and is set to High Accuracy\n- Check if location permission"
10-
" to the app is enabled\n- Close the App and open Google Maps. "
11-
"If location gets available to Maps then reopen this App."
12-
" It will detect location.";
6+
static const String locationNotAvailable = "Location not available!";
137

148
static const String errorInternetError =
159
"Internet not available\nPlease check your wifi or mobile data";

lib/src/core/location_info/location_info.dart

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)