39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class UserPreferences {
|
|
static List<String> _savedLocations = [];
|
|
static SharedPreferences? preferences;
|
|
static Future<void> init() async {
|
|
preferences = await SharedPreferences.getInstance();
|
|
_savedLocations = preferences!.getStringList('savedLocations') ?? [];
|
|
}
|
|
|
|
static List<String> getSavedLocations() {
|
|
return _savedLocations;
|
|
}
|
|
|
|
static List<String> saveNewLocation(String name, double lat, double lon) {
|
|
_savedLocations.add(name);
|
|
preferences!.setStringList('savedLocations', _savedLocations);
|
|
preferences!.setDouble("$name-lat", lat);
|
|
preferences!.setDouble("$name-lon", lon);
|
|
return getSavedLocations();
|
|
}
|
|
|
|
static List<String> deleteLocation(String name) {
|
|
preferences!.remove("$name-lat");
|
|
preferences!.remove("$name-lon");
|
|
_savedLocations.remove(name);
|
|
preferences!.remove(name);
|
|
return getSavedLocations();
|
|
}
|
|
|
|
static getLat(String name) {
|
|
return preferences!.getDouble("$name-lat");
|
|
}
|
|
|
|
static getLon(String name) {
|
|
return preferences!.getDouble("$name-lon");
|
|
}
|
|
}
|