getCurrentLocationData method
Implementation
Future<LocationDataModel?> getCurrentLocationData() async {
bool isEnabled = await isLocationServiceEnabled();
if (!isEnabled) {
isEnabled = await requestEnableLocationService();
}
if (isEnabled) {
PermissionHandlerHelperModel? permissionHandlerHelperModel = await PermissionHelperUtil.instance.checkIfLocationPermissionGranted();
if (permissionHandlerHelperModel == null) {
return LocationDataModel(locationData: null, locationResultsEnum: LocationResultsEnums.permissionHelperModelIsNull);
}
if (permissionHandlerHelperModel.permissionsResult == LocationResultsEnums.permissionGranted) {
//get location here
LocationData locationData = await Location().getLocation();
return LocationDataModel(locationData: locationData, locationResultsEnum: LocationResultsEnums.permissionGranted);
} else if (permissionHandlerHelperModel.permissionsResult == LocationResultsEnums.permissionDenied) {
return LocationDataModel(locationData: null, locationResultsEnum: LocationResultsEnums.permissionDenied);
} else if (permissionHandlerHelperModel.permissionsResult == LocationResultsEnums.permissionPermanentlyDenied) {
return LocationDataModel(locationData: null, locationResultsEnum: LocationResultsEnums.permissionPermanentlyDenied);
} else {
return LocationDataModel(locationData: null, locationResultsEnum: LocationResultsEnums.unknownIssue);
}
} else {
return LocationDataModel(locationData: null, locationResultsEnum: LocationResultsEnums.locationServicesDisabled);
}
}