import 'dart:async'; import 'dart:convert'; import 'package:shared_preferences/src/shared_preferences_legacy.dart'; import '../globals.dart' as globals; import 'yourLocation.dart'; const String locationKey = 'yourlocations'; Future> loadYourLocations() async { return globals.prefs.then((SharedPreferences prefs) { final List? yourLocations = prefs.getStringList(locationKey); final List persistedList = []; for (final String locationString in (yourLocations ?? [])) { final Map locationMap = json.decode(locationString) as Map; persistedList.add(YourLocation.fromJson(locationMap)); } return persistedList; }); } void persistYourLocations(List yl) { // debugPrint('Persisting $yl'); globals.prefs.then((SharedPreferences prefs) { final List ylAsString = []; yl.whereType().forEach((YourLocation location) { ylAsString.add(json.encode(location.toJson())); }); prefs.setStringList(locationKey, ylAsString); }); }