From 1dbe8b9a787eef6fefbea8bec696003713f37512 Mon Sep 17 00:00:00 2001 From: Taranjeet Singh Date: Fri, 16 Aug 2024 15:11:29 +0530 Subject: [PATCH] feat!(location_info): make nav key nullable Signed-off-by: Taranjeet Singh --- example/pubspec.lock | 16 ++++++++ lib/src/core/location_info/location_info.dart | 39 +++++++++++-------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 01759bc..2e97d00 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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: diff --git a/lib/src/core/location_info/location_info.dart b/lib/src/core/location_info/location_info.dart index 21d7e61..6496748 100644 --- a/lib/src/core/location_info/location_info.dart +++ b/lib/src/core/location_info/location_info.dart @@ -32,7 +32,7 @@ abstract class LocationInfo { } class LocationInfoImpl implements LocationInfo { - final GlobalKey navKey; + final GlobalKey? navKey; final bool enforceGeocoding; @@ -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(); @@ -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(); - }, - ), - )); + ); + } } }); }