Flutter ios location fetching not working at begin of utility

0
17
Flutter ios location fetching not working at begin of utility


I’m constructing an utility for prayer timings to fetch present location prayer. its working positive on android emulator however for ios machine in addition to ios emulator its not working. Its taking to siri, search web page for getting loication entry however nothing there to pick/allow location for my app then app is throwing out error, null verify operator used on null worth

I’ve location.dart file as given under

import 'bundle:geolocator/geolocator.dart';
import 'bundle:permission_handler/permission_handler.dart';
import 'bundle:geocoding/geocoding.dart';

class AppLocation {
  double? latitude;
  double? longitude;
  String? cityName;
  String? countryName;

  // Operate to get the present location
  Future getCurrentLocation() async {
    strive {
      // Verify if permission is already granted
      bool isPermissionGranted = await Permission.locationWhenInUse.isGranted;

      // Request location permission if not already granted
      if (!isPermissionGranted) {
        PermissionStatus permission = await Permission.locationWhenInUse.request();
        isPermissionGranted = permission.isGranted;
      }

      if (isPermissionGranted) {
        // Fetch the present location if permission is granted
        Place place = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.excessive);

        latitude = place.latitude;
        longitude = place.longitude;

        if (latitude != null && longitude != null) {
          await getCityAndCountryName(latitude!, longitude!);
        } else {
          print('Error: Latitude or Longitude is null.');
        }
      } else if (await Permission.locationWhenInUse.isDenied) {
        print('Location permission denied.');
        await openAppSettings(); // Optionally immediate the person to allow permissions in settings
      } else if (await Permission.locationWhenInUse.isPermanentlyDenied) {
        print('Location permission completely denied.');
        await openAppSettings(); // Direct person to app settings
      }
    } catch (e) {
      print('Error occurred whereas fetching location: $e');
    }
  }

  // Operate to get the town and nation identify based mostly on coordinates
  Future getCityAndCountryName(double latitude, double longitude) async {
    strive {
      Listing placemarks = await placemarkFromCoordinates(latitude, longitude);
      if (placemarks.isNotEmpty) {
        cityName = placemarks.first.locality ?? 'Unknown Metropolis';
        countryName = placemarks.first.nation ?? 'Unknown Nation';
      } else {
        print('No placemarks discovered');
        cityName="Unknown";
        countryName="Unknown";
      }
    } catch (e) {
      print('Error occurred whereas fetching metropolis and nation identify: $e');
      cityName="Unknown";
      countryName="Unknown";
    }
  }

  // Operate to get coordinates from a metropolis identify
  Future> getCoordinatesFromCity(String cityName) async {
    strive {
      Listing areas = await locationFromAddress(cityName);
      if (areas.isNotEmpty) {
        return {
          'latitude': areas.first.latitude,
          'longitude': areas.first.longitude,
        };
      } else {
        throw Exception('No areas discovered for the offered metropolis identify');
      }
    } catch (e) {
      throw Exception('Error occurred whereas fetching coordinates: $e');
    }
  }
}

Podfile

post_install do |installer|
  installer.pods_project.targets.every do |goal|
    flutter_additional_ios_build_settings(goal)
    goal.build_configurations.every do |config|
      # You possibly can take away unused permissions right here
      # for extra data: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/permission_handler/ios/Lessons/PermissionHandlerEnums.h
      # e.g. when you do not want digicam permission, simply add 'PERMISSION_CAMERA=0'
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.calendar
        'PERMISSION_EVENTS=0',

        ## dart: PermissionGroup.reminders
        'PERMISSION_REMINDERS=0',

        ## dart: PermissionGroup.contacts
        'PERMISSION_CONTACTS=0',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=0',

        ## dart: PermissionGroup.microphone
        'PERMISSION_MICROPHONE=0',

        ## dart: PermissionGroup.speech
        'PERMISSION_SPEECH_RECOGNIZER=0',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=0',

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        'PERMISSION_LOCATION=1',  # Allow location permission

        ## dart: PermissionGroup.notification
        'PERMISSION_NOTIFICATIONS=0',

        ## dart: PermissionGroup.mediaLibrary
        'PERMISSION_MEDIA_LIBRARY=0',

        ## dart: PermissionGroup.sensors
        'PERMISSION_SENSORS=0'
      ]
    finish
  finish
finish

Data.Plist File






    
    NSLocationWhenInUseUsageDescription
    Want location when in use
    NSLocationAlwaysAndWhenInUseUsageDescription
    All the time and when in use!
    NSLocationUsageDescription
    Older units want location.
    NSLocationAlwaysUsageDescription
    Can I've location at all times?
    CFBundleDevelopmentRegion
    $(DEVELOPMENT_LANGUAGE)
    CFBundleDisplayName
    Namazpro
    CFBundleExecutable
    $(EXECUTABLE_NAME)
    CFBundleIdentifier
    $(PRODUCT_BUNDLE_IDENTIFIER)
    CFBundleInfoDictionaryVersion
    6.0
    CFBundleName
    namazpro
    CFBundlePackageType
    APPL
    CFBundleShortVersionString
    $(FLUTTER_BUILD_NAME)
    CFBundleSignature
    ????
    CFBundleVersion
    $(FLUTTER_BUILD_NUMBER)
    LSRequiresIPhoneOS
    
    UILaunchStoryboardName
    LaunchScreen
    UIMainStoryboardFile
    Important
    UISupportedInterfaceOrientations
    
        UIInterfaceOrientationPortrait
        UIInterfaceOrientationLandscapeLeft
        UIInterfaceOrientationLandscapeRight
    
    UISupportedInterfaceOrientations~ipad
    
        UIInterfaceOrientationPortrait
        UIInterfaceOrientationPortraitUpsideDown
        UIInterfaceOrientationLandscapeLeft
        UIInterfaceOrientationLandscapeRight
    
    CADisableMinimumFrameDurationOnPhone
    
    UIApplicationSupportsIndirectInputEvents
    


LEAVE A REPLY

Please enter your comment!
Please enter your name here