Your locations persist
This commit is contained in:
parent
ce2b65f1e0
commit
7fbe5b971d
10 changed files with 140 additions and 182 deletions
20
lib/basicLocationPersist.dart
Normal file
20
lib/basicLocationPersist.dart
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue