overhaul using a trip struct that notifies its ui dependencies
All checks were successful
Build and push docker image / Build (pull_request) Successful in 1m54s
Build and release APK / Build APK (pull_request) Successful in 5m32s

This commit is contained in:
2024-08-03 16:52:29 +02:00
parent 5748630b99
commit c87a01b2e8
15 changed files with 324 additions and 164 deletions

View File

@@ -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;
}

View File

@@ -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(