Your locations persist

This commit is contained in:
vjrj 2018-06-09 23:08:23 +02:00
parent ce2b65f1e0
commit 7fbe5b971d
10 changed files with 140 additions and 182 deletions

View file

@ -0,0 +1,20 @@
import 'dart:convert';
import 'basicLocation.dart';
import 'globals.dart' as globals;
final String locationKey = 'yourlocations';
void loadYourLocations(prefs) {
List<String> yourLocations = prefs.getStringList(locationKey);
yourLocations.forEach((locationString) {
Map locationMap = json.decode(locationString);
globals.yourLocations.add(BasicLocation.fromJson(locationMap));
});
}
persistYourLocations(prefs) {
List<String> yourLocationsAsString = [];
globals.yourLocations.forEach((location) {
yourLocationsAsString.add(json.encode(location.toJson()));
});
prefs.setStringList(locationKey, yourLocationsAsString);
}