Skip to content

Commit

Permalink
feat!(location_info): make nav key nullable
Browse files Browse the repository at this point in the history
Signed-off-by: Taranjeet Singh <[email protected]>
  • Loading branch information
singhtaranjeet committed Aug 16, 2024
1 parent 57cd492 commit 1dbe8b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
16 changes: 16 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
file_picker:
dependency: transitive
description:
name: file_picker
sha256: "2ca051989f69d1b2ca012b2cf3ccf78c70d40144f0861ff2c063493f7c8c3d45"
url: "https://pub.dev"
source: hosted
version: "8.0.5"
file_selector_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -947,6 +955,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
open_file:
dependency: transitive
description:
name: open_file
sha256: a5a32d44acb7c899987d0999e1e3cbb0a0f1adebbf41ac813ec6d2d8faa0af20
url: "https://pub.dev"
source: hosted
version: "3.3.2"
package_info_plus:
dependency: transitive
description:
Expand Down
39 changes: 22 additions & 17 deletions lib/src/core/location_info/location_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class LocationInfo {
}

class LocationInfoImpl implements LocationInfo {
final GlobalKey<NavigatorState> navKey;
final GlobalKey<NavigatorState>? navKey;

final bool enforceGeocoding;

Expand All @@ -58,11 +58,13 @@ class LocationInfoImpl implements LocationInfo {
final permissionStatus = await Geolocator.checkPermission();

if (!_isPermissionGranted(permissionStatus)) {
await DialogUtils.showAlertDialog(
title: 'Location Permission Required!',
content: defaultLocationReason,
actionText: 'OKAY GOT IT',
navKey: navKey);
if (navKey != null) {
await DialogUtils.showAlertDialog(
title: 'Location Permission Required!',
content: defaultLocationReason,
actionText: 'OKAY GOT IT',
navKey: navKey!);
}
}

final permission = await Geolocator.requestPermission();
Expand Down Expand Up @@ -231,18 +233,21 @@ class LocationInfoImpl implements LocationInfo {
final geolocationStatus = await Geolocator.isLocationServiceEnabled();
if (!_isPermissionGranted(permission) || !geolocationStatus) {
t.cancel();

await navKey.currentState!.push(MaterialPageRoute(
builder: (_) => AppErrorPage(
LocationException(
'${Constants.locationNotAvailable}'
'\n$defaultLocationReason',
if (navKey != null) {
await navKey!.currentState!.push(
MaterialPageRoute(
builder: (_) => AppErrorPage(
LocationException(
'${Constants.locationNotAvailable}'
'\n$defaultLocationReason',
),
onRetryTap: () {
initLocation();
},
),
),
onRetryTap: () {
initLocation();
},
),
));
);
}
}
});
}
Expand Down

0 comments on commit 1dbe8b9

Please sign in to comment.