frontend groundwork
This commit is contained in:
45
frontend/lib/utils/fetch_trip.dart
Normal file
45
frontend/lib/utils/fetch_trip.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:anyway/constants.dart';
|
||||
import "package:anyway/structs/landmark.dart";
|
||||
import "package:anyway/structs/trip.dart";
|
||||
import "package:anyway/structs/preferences.dart";
|
||||
|
||||
import "package:anyway/structs/linked_landmarks.dart";
|
||||
|
||||
Dio dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: API_URL_BASE,
|
||||
connectTimeout: const Duration(seconds: 5),
|
||||
receiveTimeout: const Duration(seconds: 60),
|
||||
// api is notoriously slow
|
||||
// headers: {
|
||||
// HttpHeaders.userAgentHeader: 'dio',
|
||||
// 'api': '1.0.0',
|
||||
// },
|
||||
contentType: Headers.jsonContentType,
|
||||
responseType: ResponseType.json,
|
||||
),
|
||||
);
|
||||
|
||||
Future<Trip> fetchTrip(
|
||||
List<double> startPoint,
|
||||
UserPreferences preferences,
|
||||
) async {
|
||||
final response = await dio.post(
|
||||
"/trip/new",
|
||||
data: {
|
||||
// 'preferences': preferences.toJson(),
|
||||
'start': [48,2.3]
|
||||
}
|
||||
);
|
||||
|
||||
// handle errors
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to load trip');
|
||||
}
|
||||
if (response.data["error"] != null) {
|
||||
throw Exception(response.data["error"]);
|
||||
}
|
||||
return Trip.fromJson(response.data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user