I want it so the function _getCurrentLocation() would be called repeatably and automatically so I wouldn't have to press the button to update the text. I don't really need the button, but I don't know how to do it differently.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("GPS"),
backgroundColor: Colors.red[600],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (_currentPosition != null)
for(var i=0; i<751;i++)
if((mas[i][0]<=_currentPosition.latitude) && (mas[i][1]<=_currentPosition.longitude) && (mas2[i][0]>=_currentPosition.latitude) && (mas2[i][1]>=_currentPosition.longitude))
Text(
"LAT: ${_currentPosition.latitude}, LNG: ${_currentPosition.longitude},${mas3[i]}"),
FlatButton(
child: Text("koordinātes"),
onPressed: () {
_getCurrentLocation();
},
),
],
),
),
);
}
_getCurrentLocation() {
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position) {
setState(() {
_currentPosition = position;
var globals;
});
}).catchError((e) {
print(e);
});
}
}