// Represents a collection of landmarks that represent a journey // Different instances of a Trip can be saved and loaded by the user import 'dart:collection'; import 'dart:convert'; import 'package:fast_network_navigation/structs/landmark.dart'; import 'package:shared_preferences/shared_preferences.dart'; class Trip { final String uuid; final String cityName; // TODO: cityName should be inferred from coordinates of the Landmarks final LinkedList landmarks; // could be empty as well Trip({ required this.uuid, required this.cityName, required this.landmarks, }); factory Trip.fromJson(Map json) { return Trip( uuid: json['uuid'], cityName: json['cityName'], landmarks: LinkedList() ); } factory Trip.fromPrefs(SharedPreferences prefs, String uuid) { String? content = prefs.getString('trip_$uuid'); Map json = jsonDecode(content!); Trip trip = Trip.fromJson(json); String? firstUUID = json['entry_uuid']; appendLandmarks(trip.landmarks, prefs, firstUUID); return trip; } } // Helper appendLandmarks(LinkedList landmarks, SharedPreferences prefs, String? firstUUID) { while (firstUUID != null) { var (head, nextUUID) = getLandmarkFromPrefs(prefs, firstUUID); landmarks.add(head); firstUUID = nextUUID; } }