trying to get user current location using geolocator package

Troubleshooting

Hello,

I am trying to get the user current location with below custom action code:

// Automatic FlutterFlow imports

import '/backend/backend.dart';

import '/flutter_flow/flutter_flow_theme.dart';

import '/flutter_flow/flutter_flow_util.dart';

import '/custom_code/actions/index.dart'; // Imports other custom actions

import '/flutter_flow/custom_functions.dart'; // Imports custom functions

import 'package:flutter/material.dart';

// Begin custom action code

// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

 

import 'package:geolocator/geolocator.dart';

import '/flutter_flow/lat_lng.dart';

 

Future<LatLng> getCurrentLocation() async {

  bool serviceEnabled;

  LocationPermission permission;

 

  // Step 1: Check if location services are enabled

  serviceEnabled = await Geolocator.isLocationServiceEnabled();

  if (!serviceEnabled) {

    return Future.error('Location services are disabled.');

  }

 

  // Step 2: Check and request permissions

  permission = await Geolocator.checkPermission();

  if (permission == LocationPermission.denied) {

    permission = await Geolocator.requestPermission();

    if (permission == LocationPermission.denied) {

      return Future.error('Location permissions are denied');

    }

  }

 

  if (permission == LocationPermission.deniedForever) {

    return Future.error('Location permissions are permanently denied');

  }

 

  // ✅ Step 3: Get current position (no deprecated parameters)

  Position position = await Geolocator.getCurrentPosition();

 

  return LatLng(position.latitude, position.longitude);

}

and on login page I am configuring the action on page load action with above custom action code and mapping the custom action output to app state variable "userLocation" datatype latlng with new action as update app state, but in web preview I am getting the userLocation=0,0 (which is default value i have defined at the time of app state creation)


As I am beginner to flutterflow, trying to learn, can someone help to get the above issue gets resolved

What have you tried so far?

tried to change the return datatype also, but didnt worked

Did you check FlutterFlow's Documentation for this topic?
No
2