diff --git a/lib/managers/location_manager.class.dart b/lib/managers/location_manager.class.dart index 7d2aa1f..ff20f6e 100644 --- a/lib/managers/location_manager.class.dart +++ b/lib/managers/location_manager.class.dart @@ -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); diff --git a/lib/pages/integration_settings.page.dart b/lib/pages/integration_settings.page.dart index 41216ca..6d231ee 100644 --- a/lib/pages/integration_settings.page.dart +++ b/lib/pages/integration_settings.page.dart @@ -13,6 +13,7 @@ class _IntegrationSettingsPageState extends State { int _locationInterval = LocationManager().defaultUpdateIntervalMinutes; bool _locationTrackingEnabled = false; + bool _wait = false; @override void initState() { @@ -108,13 +109,15 @@ class _IntegrationSettingsPageState extends State { 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; + }); }); }, ),