diff --git a/lib/core/location_util.dart b/lib/core/location_util.dart index 567bc59..487b228 100644 --- a/lib/core/location_util.dart +++ b/lib/core/location_util.dart @@ -36,22 +36,60 @@ class LocationUtils { isGMSDevice = GmsCheck().checkGmsAvailability(); } - void getLocation({Function(LatLng)? onSuccess, VoidCallback? onFailure,bool isShowConfirmDialog = false}) async { + // final defaultCallbackForLocationDenied = (){ + // showCommonBottomSheetWithoutHeight( + // title: LocaleKeys.notice.tr(context: navigationService.navigatorKey.currentContext!), + // navigationService.navigatorKey.currentContext!, + // child: Utils.getWarningWidget( + // loadingText: + // "Please grant location permission from app settings to see better results" + // .needTranslation, + // isShowActionButtons: true, + // onCancelTap: () { + // navigationService.pop(); + // }, + // onConfirmTap: () async { + // navigationService.pop(); + // openAppSettings(); + // }), + // callBackFunc: () {}, + // isFullScreen: false, + // isCloseButtonVisible: true, + // ); + // } + + void getLocation( + {Function(LatLng)? onSuccess, + VoidCallback? onFailure, + bool isShowConfirmDialog = false, + VoidCallback? onLocationDeniedForever}) async { this.isShowConfirmDialog = isShowConfirmDialog; if (Platform.isIOS) { - getCurrentLocation(onFailure: onFailure, onSuccess: onSuccess); + getCurrentLocation( + onFailure: onFailure, + onSuccess: onSuccess, + onLocationDeniedForever: onLocationDeniedForever); return; } if (await isGMSDevice ?? true) { - getCurrentLocation(onFailure: onFailure, onSuccess: onSuccess); + getCurrentLocation( + onFailure: onFailure, + onSuccess: onSuccess, + onLocationDeniedForever: onLocationDeniedForever); return; } - getHMSLocation(onFailure: onFailure, onSuccess: onSuccess); + getHMSLocation( + onFailure: onFailure, + onSuccess: onSuccess, + onLocationDeniedForever: onLocationDeniedForever); } - void getCurrentLocation({Function(LatLng)? onSuccess, VoidCallback? onFailure, }) async { + void getCurrentLocation( + {Function(LatLng)? onSuccess, + VoidCallback? onFailure, + VoidCallback? onLocationDeniedForever}) async { var location = Location(); bool isLocationEnabled = await location.serviceEnabled(); @@ -74,14 +112,15 @@ class LocationUtils { return; } } else if (permissionGranted == LocationPermission.deniedForever) { - if (onFailure == null && isShowConfirmDialog) { + appState.resetLocation(); + if(onLocationDeniedForever == null && isShowConfirmDialog){ showCommonBottomSheetWithoutHeight( title: LocaleKeys.notice.tr(context: navigationService.navigatorKey.currentContext!), navigationService.navigatorKey.currentContext!, child: Utils.getWarningWidget( loadingText: - "Please grant location permission from app settings to see better results" - .needTranslation, + "Please grant location permission from app settings to see better results" + .needTranslation, isShowActionButtons: true, onCancelTap: () { navigationService.pop(); @@ -94,9 +133,8 @@ class LocationUtils { isFullScreen: false, isCloseButtonVisible: true, ); - return; } - onFailure?.call(); + onLocationDeniedForever?.call(); return; } @@ -215,7 +253,10 @@ class LocationUtils { appState.userLong = locationData.longitude; } - void getHMSLocation({VoidCallback? onFailure, Function(LatLng p1)? onSuccess}) async { + void getHMSLocation( + {VoidCallback? onFailure, + Function(LatLng p1)? onSuccess, + VoidCallback? onLocationDeniedForever}) async { try { var location = Location(); HmsLocation.FusedLocationProviderClient locationService = HmsLocation.FusedLocationProviderClient()..initFusedLocationService(); @@ -236,7 +277,32 @@ class LocationUtils { LocationPermission permissionGranted = await Geolocator.checkPermission(); if (permissionGranted == LocationPermission.denied) { permissionGranted = await Geolocator.requestPermission(); - if (permissionGranted != LocationPermission.whileInUse && permissionGranted != LocationPermission.always) { + if (permissionGranted == LocationPermission.deniedForever) { + appState.resetLocation(); + if(onLocationDeniedForever == null && isShowConfirmDialog){ + showCommonBottomSheetWithoutHeight( + title: LocaleKeys.notice.tr(context: navigationService.navigatorKey.currentContext!), + navigationService.navigatorKey.currentContext!, + child: Utils.getWarningWidget( + loadingText: + "Please grant location permission from app settings to see better results" + .needTranslation, + isShowActionButtons: true, + onCancelTap: () { + navigationService.pop(); + }, + onConfirmTap: () async { + navigationService.pop(); + openAppSettings(); + }), + callBackFunc: () {}, + isFullScreen: false, + isCloseButtonVisible: true, + ); + } + onLocationDeniedForever?.call(); + return; + } else if (permissionGranted != LocationPermission.whileInUse && permissionGranted != LocationPermission.always) { appState.resetLocation(); onFailure?.call(); return; diff --git a/lib/core/utils/utils.dart b/lib/core/utils/utils.dart index c4a2db8..ae49018 100644 --- a/lib/core/utils/utils.dart +++ b/lib/core/utils/utils.dart @@ -643,12 +643,17 @@ class Utils { } /// Widget to build an SVG from network - static Widget buildImgWithNetwork({required String url, required Color iconColor, bool isDisabled = false, double width = 24, double height = 24, BoxFit fit = BoxFit.cover}) { + static Widget buildImgWithNetwork({required String url, required Color iconColor, bool isDisabled = false, double width = 24, double height = 24, BoxFit fit = BoxFit.cover, ImageErrorWidgetBuilder? errorBuilder}) { return Image.network( url, width: width, height: height, fit: fit, + errorBuilder: errorBuilder??(_,__,___){ + //todo change the error builder icon that it is returning + return Utils.buildSvgWithAssets(width: width, + height: height,icon: AppAssets.no_visit_icon); + }, ); }