From f8ce088a0b691c6364316a45698c229299f4b9ff Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 10 Jun 2025 07:37:09 -0700 Subject: [PATCH] Don't reset distance value --- lib/preferences.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/preferences.dart b/lib/preferences.dart index 2a1e233..0774db2 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -35,7 +35,8 @@ class Preferences { } if (instance.get(distance) is String) { final stringValue = instance.getString(distance); - await instance.setInt(distance, int.tryParse(stringValue ?? '') ?? 75); + final intValue = int.tryParse(stringValue ?? '') ?? 75; + await instance.setInt(distance, intValue > 0 ? intValue : 75); } } else { await _migrate(); @@ -44,10 +45,7 @@ class Preferences { await instance.setString(url, instance.getString(url) ?? 'http://demo.traccar.org:5055'); await instance.setString(accuracy, instance.getString(accuracy) ?? 'medium'); await instance.setInt(interval, instance.getInt(interval) ?? 300); - final distanceValue = instance.getInt(distance); - if (distanceValue == null || distanceValue <= 0) { - await instance.setInt(distance, 75); - } + await instance.setInt(distance, instance.getInt(distance) ?? 75); await instance.setBool(buffer, instance.getBool(buffer) ?? true); } @@ -131,7 +129,7 @@ class Preferences { final oldDistanceString = instance.getString('distance_preference'); final oldDistance = oldDistanceString != null ? int.tryParse(oldDistanceString) : null; if (oldDistance != null) { - instance.setInt(distance, oldDistance); + instance.setInt(distance, oldDistance > 0 ? oldDistance : 75); instance.remove('distance_preference'); } final oldBuffer = instance.getBool('buffer_preference');