To implement this, follow these steps:
- Modify the getPosition() method. This will wait 3 seconds and then retrieve the current device's position (see the previous recipe for the complete code):
Future<Position> getPosition() async {
await Future<int>.delayed(const Duration(seconds: 3));
Position position = await
Geolocator().getLastKnownPosition(desiredAccuracy:
LocationAccuracy.high);
return position;
}
- Write the following code in the build method of the State class:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Current Location')),
body: Center(child: FutureBuilder(
future: getPosition(),
builder: (BuildContext context, AsyncSnapshot<dynamic>
snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return CircularProgressIndicator();
}
else if (snapshot.connectionState...