Load user preferences at start of app. Manage locations: user is able to add locations by lat and lon to shared preferences
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user