Integration settings improvements

This commit is contained in:
Yegor Vialov
2019-10-24 18:58:48 +00:00
parent 4068b295bd
commit 283ae6cfd4
2 changed files with 9 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class LocationManager {
}
}
void setSettings(bool enabled, int interval) async {
setSettings(bool enabled, int interval) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (interval != _updateInterval.inMinutes) {
prefs.setInt("location-interval", interval);

View File

@ -13,6 +13,7 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
int _locationInterval = LocationManager().defaultUpdateIntervalMinutes;
bool _locationTrackingEnabled = false;
bool _wait = false;
@override
void initState() {
@ -108,13 +109,15 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
Text("Enable device location tracking"),
Switch(
value: _locationTrackingEnabled,
onChanged: (value) {
SharedPreferences.getInstance().then((prefs) => prefs.setBool("location-enabled", value));
if (value) {
LocationManager().updateDeviceLocation();
}
onChanged: _wait ? null : (value) {
setState(() {
_locationTrackingEnabled = value;
_wait = true;
});
LocationManager().setSettings(_locationTrackingEnabled, _locationInterval).then((_){
setState(() {
_wait = false;
});
});
},
),