From 23218c22d735723e557c8f9397d5c9664d63c755 Mon Sep 17 00:00:00 2001 From: Supermjork Date: Sat, 30 Dec 2023 22:53:30 +0200 Subject: [PATCH] Arrival data can be shown on click --- lib/fetcher.dart | 41 ++++++++++++++++++++++++++++++++++++++++- lib/input_data.dart | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/fetcher.dart b/lib/fetcher.dart index 5d8d651..002e8e4 100644 --- a/lib/fetcher.dart +++ b/lib/fetcher.dart @@ -51,6 +51,9 @@ class _FetchAPIState extends State { title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"), titleAlignment: ListTileTitleAlignment.center, subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"), + onTap: () => { + showArrivalInfo(context, snapshot.data![index]) + }, ); }, ); @@ -107,5 +110,41 @@ String weekNumToString(int weekday) { return "Sunday"; } - throw "AAAAAAAAA"; + throw "Week Day Parse Error"; +} + +showArrivalInfo(BuildContext context, Arrival data) { + // set up the button + Widget okButton = TextButton( + child: const Text("Back"), + onPressed: () { + Navigator.pop(context); + }, + ); + + // set up the AlertDialog + AlertDialog alert = AlertDialog( + title: const Text("Selected Arrival Info"), + content: Text("Tram Colour: JSON DOESN'T HAVE COLOUR\n\nChosen Line: ${data.tramLine}\n\nDirection: ${directionParse(data.direction)}\n\nSubmitted On: ${data.timeOfDay} (Needs to include date)"), + actions: [ + okButton, + ], + ); + + // show the dialog + showDialog( + context: context, + builder: (BuildContext context) { + return alert; + }, + ); +} + +String directionParse(bool direction) { + switch (direction) { + case true: + return "Raml"; + case false: + return "Victoria"; + } } diff --git a/lib/input_data.dart b/lib/input_data.dart index e5bb40f..c004027 100644 --- a/lib/input_data.dart +++ b/lib/input_data.dart @@ -205,7 +205,7 @@ class _InputDataState extends State { } } -showAlertDialog(BuildContext context, int chosenLine, String chosenColour, String chosenDir, String submissionDate) { +showSubmissionSuccess(BuildContext context, int chosenLine, String chosenColour, String chosenDir, String submissionDate) { // Delay (I want the splash to show) //Future.delayed(const Duration(milliseconds: 200));