feat(route building): add time constraint for departure requests

This commit is contained in:
fbachus
2026-07-31 04:10:02 +02:00
parent 5ead82b9c6
commit 1cf594ed42
2 changed files with 19 additions and 2 deletions
+12 -1
View File
@@ -6,6 +6,14 @@ import 'dart:convert';
import 'transport_helper.dart';
String timeOf(DateTime fullDT) {
// doing it this way so we always get two digits on the hour
String full = fullDT.toString();
List<String> splits = full.split(" ")[1].split(":");
String time = '${splits[0]}:${splits[1]}';
return time;
}
class ApiHandler {
// TODO: Split next line for better Error Handling
static final String baseUrl = dotenv.get("VBB_API_URL");
@@ -79,6 +87,7 @@ class ApiHandler {
static Future<List<Departure>> departures(
String stationId, {
int? maxDepartures = -1,
DateTime? time,
int? duration = 0,
}) async {
String urlPath = '/api/fahrinfo/latest/departureBoard';
@@ -87,7 +96,9 @@ class ApiHandler {
Uri url = Uri.https(baseUrl, urlPath, {
'accessId': accessID,
'id': stationString,
////'time': /current time //time from which departures will be shown
'time': timeOf(
time ?? DateTime.now(),
), //time from which departures will be shown
'duration': duration.toString(), //interval time in minutes
'maxJourneys': maxDepartures.toString(),
//'type': 'S', // Station/Stops only
+7 -1
View File
@@ -273,9 +273,11 @@ class StationList extends StatelessWidget {
class ChooseDeparturePage extends StatefulWidget {
final Station startStation;
final int? journeyId;
final Departure? arrival;
const ChooseDeparturePage({
super.key,
this.journeyId,
this.arrival,
required this.startStation,
});
@@ -288,7 +290,10 @@ class _ChooseDeparturePageState extends State<ChooseDeparturePage> {
Journey? singleJourney;
void loadDepartures(Station startStation) async {
departureList = await ApiHandler.departures(startStation.id);
departureList = await ApiHandler.departures(
startStation.id,
time: widget.arrival?.arrivalTime ?? DateTime.now(),
);
setState(() {});
}
@@ -470,6 +475,7 @@ class _ChooseArrivalPageState extends State<ChooseArrivalPage> {
builder: (context) => ChooseDeparturePage(
startStation: startStation,
journeyId: journeyId,
arrival: arrival,
),
),
);