There is no way to know exactly how long an asynchronous task might take, so it would be a good idea to give the user some feedback while the device is retrieving the current position, with a CircularProgressIndicator. What we want to achieve is to show the animation while the position is being retrieved, and as soon as the coordinates become available, hide the animation, and show the coordinates. We can achieve that with the following code in the build() method:
@override
Widget build(BuildContext context) {
Widget myWidget;
if (myPosition == '') {
myWidget = CircularProgressIndicator();
} else {
myWidget = Text(myPosition);
}
return Scaffold(
appBar: AppBar(title: Text('Current Location')),
body: Center(child:myWidget),
);
}
If you cannot see the animation of the CircularProgressIndicator, it might mean your device is too fast: try purposely adding a delay before the Geolocator() call, with the instruction...