Server sends StopState instead of String

This commit is contained in:
Levi Lesches 2025-05-04 20:19:51 -04:00
parent e8de6475c7
commit 1c5c6c9f11
2 changed files with 9 additions and 16 deletions

View file

@ -2,6 +2,7 @@ import "package:flutter/foundation.dart" show debugPrint, kDebugMode;
import "package:client/data.dart";
import "package:http/http.dart" as http;
import "package:shared/graph.dart";
import "api_client.dart";
import "service.dart";
@ -19,27 +20,20 @@ class ApiService extends Service {
? Uri(path: "api/")
: Uri(scheme: "http", host: "localhost", port: 8001);
Future<String?> getPath({
Future<List<StopState>?> getPath({
required Coordinates start,
required Coordinates end,
}) async {
final uri = _base.resolve("/path").replace(
}) => _client.getJsonList(
_base.resolve("/path").replace(
queryParameters: {
"start_lat": start.lat.toString(),
"start_lon": start.long.toString(),
"end_lat": end.lat.toString(),
"end_lon": end.long.toString(),
},
);
try {
final response = await http.get(uri);
return response.body;
// Any error should show null
// ignore: avoid_catches_without_on_clauses
} catch (error) {
return null;
}
}
),
StopState.fromJson,
);
Future<List<Route>?> getRoutes() => _client.getJsonList(
_base.resolve("/routes"),

View file

@ -18,7 +18,6 @@ Response getPath(Request request) {
if (path == null) {
return Response.ok("No routes found", headers: corsHeaders);
}
final buffer = StringBuffer();
explainPath(path, buffer.writeln);
return Response.ok(buffer.toString(), headers: corsHeaders);
final jsonBody = encodeJsonList(path);
return Response.ok(jsonBody, headers: corsHeaders);
}