anyway/frontend/lib/utils/load_trips.dart
Remy Moll db41528702
Some checks failed
Build and push docker image / Build (pull_request) Failing after 3m5s
Build and release APK / Build APK (pull_request) Successful in 7m24s
Build web / Build Web (pull_request) Successful in 3m36s
functional datastructure. Needs to be able to write to storage as well
2024-06-21 19:30:40 +02:00

45 lines
1.9 KiB
Dart

import 'dart:collection';
import 'package:fast_network_navigation/structs/linked_landmarks.dart';
import 'package:fast_network_navigation/structs/trip.dart';
import 'package:fast_network_navigation/structs/landmark.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<List<Trip>> loadTrips() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<Trip> trips = [];
Set<String> keys = prefs.getKeys();
for (String key in keys) {
if (key.startsWith('trip_')) {
String uuid = key.replaceFirst('trip_', '');
trips.add(Trip.fromPrefs(prefs, uuid));
}
}
if (trips.isEmpty) {
String now = DateTime.now().toString();
trips.add(
Trip(uuid: '1', cityName: 'Paris (generated $now)', landmarks: LinkedList<Landmark>())
);
// Trip(uuid: "1", cityName: "Paris", landmarks: [
// Landmark(name: "Landmark 1", location: [48.85, 2.35], type: LandmarkType(name: "Type 1")),
// Landmark(name: "Landmark 2", location: [48.86, 2.36], type: LandmarkType(name: "Type 2")),
// Landmark(name: "Landmark 3", location: [48.75, 2.3], type: LandmarkType(name: "Type 3")),
// Landmark(name: "Landmark 4", location: [48.9, 2.4], type: LandmarkType(name: "Type 4")),
// Landmark(name: "Landmark 5", location: [48.91, 2.45], type: LandmarkType(name: "Type 5")),
// ]));
// trips.add(Trip(uuid: "2", cityName: "Vienna", landmarks: []));
// trips.add(Trip(uuid: "3", cityName: "London", landmarks: []));
// trips.add(Trip(uuid: "4", cityName: "Madrid", landmarks: []));
// trips.add(Trip(uuid: "5", cityName: "Tokyo", landmarks: []));
// trips.add(Trip(uuid: "6", cityName: "New York", landmarks: []));
// trips.add(Trip(uuid: "7", cityName: "Los Angeles", landmarks: []));
// trips.add(Trip(uuid: "8", cityName: "Zurich", landmarks: []));
// trips.add(Trip(uuid: "9", cityName: "Orschwiller", landmarks: []));
}
return trips;
}