overhaul using a trip struct that notifies its ui dependencies
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import "dart:convert"; | ||||
| import "dart:developer"; | ||||
|  | ||||
| import 'package:dio/dio.dart'; | ||||
|  | ||||
| import 'package:anyway/constants.dart'; | ||||
| import "package:anyway/structs/landmark.dart"; | ||||
| import "package:anyway/structs/trip.dart"; | ||||
| @@ -25,14 +25,14 @@ Dio dio = Dio( | ||||
|   ), | ||||
| ); | ||||
|  | ||||
| Future<Trip>? fetchTrip( | ||||
|   List<double> startPoint, | ||||
| fetchTrip( | ||||
|   Trip trip, | ||||
|   Future<UserPreferences> preferences, | ||||
| ) async { | ||||
|   UserPreferences prefs = await preferences; | ||||
|   Map<String, dynamic> data = { | ||||
|     "preferences": prefs.toJson(), | ||||
|     "start": startPoint | ||||
|     "start": trip.landmarks!.first.location, | ||||
|   }; | ||||
|   String dataString = jsonEncode(data); | ||||
|   log(dataString); | ||||
| @@ -44,24 +44,25 @@ Future<Trip>? fetchTrip( | ||||
|  | ||||
|   // handle errors | ||||
|   if (response.statusCode != 200) { | ||||
|     trip.updateUUID("error"); | ||||
|     throw Exception('Failed to load trip'); | ||||
|   } | ||||
|   if (response.data["error"] != null) { | ||||
|     trip.updateUUID("error"); | ||||
|     throw Exception(response.data["error"]); | ||||
|   } | ||||
|   log(response.data.toString()); | ||||
|   Map<String, dynamic> json = response.data; | ||||
|  | ||||
|   // only fetch the trip "meta" data for now | ||||
|   Trip trip = Trip.fromJson(json); | ||||
|   // only fill in the trip "meta" data for now | ||||
|   trip.loadFromJson(json); | ||||
|  | ||||
|   String? nextUUID = json["first_landmark_uuid"]; | ||||
|   while (nextUUID != null) { | ||||
|     var (landmark, newUUID) = await fetchLandmark(nextUUID); | ||||
|     trip.landmarks.add(landmark); | ||||
|     trip.addLandmark(landmark); | ||||
|     nextUUID = newUUID; | ||||
|   } | ||||
|   return trip; | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ Future<List<Trip>> loadTrips() async { | ||||
|   } | ||||
|  | ||||
|   if (trips.isEmpty) { | ||||
|     Trip t1 = Trip(uuid: '1', cityName: 'Paris', landmarks: LinkedList<Landmark>()); | ||||
|     Trip t1 = Trip(uuid: '1', landmarks: LinkedList<Landmark>()); | ||||
|     t1.landmarks.add( | ||||
|       Landmark( | ||||
|         uuid: '1', | ||||
| @@ -66,7 +66,7 @@ Future<List<Trip>> loadTrips() async { | ||||
|     trips.add(t1); | ||||
|  | ||||
|  | ||||
|     Trip t2 = Trip(uuid: '2', cityName: 'Vienna', landmarks: LinkedList<Landmark>()); | ||||
|     Trip t2 = Trip(uuid: '2', landmarks: LinkedList<Landmark>()); | ||||
|  | ||||
|     t2.landmarks.add( | ||||
|       Landmark( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user