Save config settings

This commit is contained in:
Anton Tananaev 2025-05-07 17:42:07 -07:00
parent 6254a50e5c
commit e2c07a23c6
2 changed files with 23 additions and 0 deletions

View file

@ -2,6 +2,7 @@
import 'dart:io';
import 'dart:math';
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
import 'package:shared_preferences/shared_preferences.dart';
class Preferences {
@ -28,6 +29,25 @@ class Preferences {
await preferences.setBool(buffer, preferences.getBool(buffer) ?? true);
}
static bg.Config geolocationConfig(SharedPreferences preferences) {
return bg.Config(
stopOnTerminate: false,
startOnBoot: true,
desiredAccuracy: switch (preferences.getString(accuracy)) {
'high' => bg.Config.DESIRED_ACCURACY_HIGH,
'low' => bg.Config.DESIRED_ACCURACY_LOW,
_ => bg.Config.DESIRED_ACCURACY_MEDIUM,
},
url: preferences.getString(url),
params: {
"device_id": preferences.getString(id),
},
distanceFilter: preferences.getInt(distance)?.toDouble(),
locationUpdateInterval: preferences.getInt(interval),
maxRecordsToPersist: preferences.getBool(buffer) != false ? -1 : 0,
);
}
static Future<void> _migrate(SharedPreferences preferences) async {
final oldId = preferences.getString('device_id_preference');
if (oldId != null) {