functional datastructure. Needs to be able to write to storage as well
This commit is contained in:
44
frontend/lib/utils/load_trips.dart
Normal file
44
frontend/lib/utils/load_trips.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user