Public Access
feat(route building): add time constraint for departure requests
This commit is contained in:
+12
-1
@@ -6,6 +6,14 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'transport_helper.dart';
|
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 {
|
class ApiHandler {
|
||||||
// TODO: Split next line for better Error Handling
|
// TODO: Split next line for better Error Handling
|
||||||
static final String baseUrl = dotenv.get("VBB_API_URL");
|
static final String baseUrl = dotenv.get("VBB_API_URL");
|
||||||
@@ -79,6 +87,7 @@ class ApiHandler {
|
|||||||
static Future<List<Departure>> departures(
|
static Future<List<Departure>> departures(
|
||||||
String stationId, {
|
String stationId, {
|
||||||
int? maxDepartures = -1,
|
int? maxDepartures = -1,
|
||||||
|
DateTime? time,
|
||||||
int? duration = 0,
|
int? duration = 0,
|
||||||
}) async {
|
}) async {
|
||||||
String urlPath = '/api/fahrinfo/latest/departureBoard';
|
String urlPath = '/api/fahrinfo/latest/departureBoard';
|
||||||
@@ -87,7 +96,9 @@ class ApiHandler {
|
|||||||
Uri url = Uri.https(baseUrl, urlPath, {
|
Uri url = Uri.https(baseUrl, urlPath, {
|
||||||
'accessId': accessID,
|
'accessId': accessID,
|
||||||
'id': stationString,
|
'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
|
'duration': duration.toString(), //interval time in minutes
|
||||||
'maxJourneys': maxDepartures.toString(),
|
'maxJourneys': maxDepartures.toString(),
|
||||||
//'type': 'S', // Station/Stops only
|
//'type': 'S', // Station/Stops only
|
||||||
|
|||||||
+7
-1
@@ -273,9 +273,11 @@ class StationList extends StatelessWidget {
|
|||||||
class ChooseDeparturePage extends StatefulWidget {
|
class ChooseDeparturePage extends StatefulWidget {
|
||||||
final Station startStation;
|
final Station startStation;
|
||||||
final int? journeyId;
|
final int? journeyId;
|
||||||
|
final Departure? arrival;
|
||||||
const ChooseDeparturePage({
|
const ChooseDeparturePage({
|
||||||
super.key,
|
super.key,
|
||||||
this.journeyId,
|
this.journeyId,
|
||||||
|
this.arrival,
|
||||||
required this.startStation,
|
required this.startStation,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -288,7 +290,10 @@ class _ChooseDeparturePageState extends State<ChooseDeparturePage> {
|
|||||||
Journey? singleJourney;
|
Journey? singleJourney;
|
||||||
|
|
||||||
void loadDepartures(Station startStation) async {
|
void loadDepartures(Station startStation) async {
|
||||||
departureList = await ApiHandler.departures(startStation.id);
|
departureList = await ApiHandler.departures(
|
||||||
|
startStation.id,
|
||||||
|
time: widget.arrival?.arrivalTime ?? DateTime.now(),
|
||||||
|
);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +475,7 @@ class _ChooseArrivalPageState extends State<ChooseArrivalPage> {
|
|||||||
builder: (context) => ChooseDeparturePage(
|
builder: (context) => ChooseDeparturePage(
|
||||||
startStation: startStation,
|
startStation: startStation,
|
||||||
journeyId: journeyId,
|
journeyId: journeyId,
|
||||||
|
arrival: arrival,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user