I am trying to use 'GeoLocator' to retrieve Latitude & Longitude. However, not able to get any output?
Also will be helpful if someone can help me organize the 'geoLocator' package as a service in a separate dart file.
As suggested I tried changing the code, but still not able to get the geolocation. Also when I call the '_determinePosition()' getting "Instance of 'Future' ".
import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { // Future<Position> _determinePosition() async { bool serviceEnabled; LocationPermission permission; // Test if location services are enabled. serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { return Future.error('Location services are disabled.'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.deniedForever) { // Permissions are denied forever, handle appropriately. return Future.error( 'Location permissions are permanently denied, we cannot request permissions.'); } if (permission == LocationPermission.denied) { return Future.error('Location permissions are denied'); } } return await Geolocator.getCurrentPosition(); } @override Widget build(BuildContext context) { // TESTIST IF PRINT CAN WORK HERE print(_determinePosition()); return Scaffold( appBar: AppBar( title: Text("Location"), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ TextButton( child: Text("Get location"), onPressed: () { // PRINTING IN THE CONSOLE _determinePosition(); }, ), ], ), ), ); } }