From 1cf594ed42e0b3900a60297280f3101bfcf70441 Mon Sep 17 00:00:00 2001 From: fbachus Date: Fri, 31 Jul 2026 03:49:23 +0200 Subject: [PATCH] feat(route building): add time constraint for departure requests --- lib/api_handler.dart | 13 ++++++++++++- lib/main.dart | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/api_handler.dart b/lib/api_handler.dart index 323ac81..40eda0e 100644 --- a/lib/api_handler.dart +++ b/lib/api_handler.dart @@ -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 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> 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 diff --git a/lib/main.dart b/lib/main.dart index 560f668..7496c41 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { 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 { builder: (context) => ChooseDeparturePage( startStation: startStation, journeyId: journeyId, + arrival: arrival, ), ), );