diff --git a/lib/app_settings.dart b/lib/app_settings.dart index fa841a4..5daab3b 100644 --- a/lib/app_settings.dart +++ b/lib/app_settings.dart @@ -9,7 +9,7 @@ class Settings extends StatefulWidget { } class _Settings extends State { - late String selectedTheme = 'Dark'; + late String selectedTheme = 'Dark'; // Default app theme @override Widget build(BuildContext context) { @@ -20,9 +20,12 @@ class _Settings extends State { body: ListView( children:[ + // List of Tiles in the Settings Screen + // Starting with App Theme ListTile( title: const Text("App Theme"), subtitle: const Text("Sets the theme of the app between: Dark, Light, System Default."), + // User Selection trailing: DropdownButton ( value: selectedTheme, items: ["Light", "Dark", "System Default"].map((String value) { @@ -31,6 +34,7 @@ class _Settings extends State { child: Text(value), ); }).toList(), + // Updating Selection onChanged: (String? updatedTheme) { setState(() { selectedTheme = updatedTheme ?? selectedTheme; diff --git a/lib/arrival.dart b/lib/arrival.dart index 1c3278c..c9b0d28 100644 --- a/lib/arrival.dart +++ b/lib/arrival.dart @@ -13,9 +13,16 @@ class Arrival { factory Arrival.fromJson(Map json) { return Arrival( + // Arrival Time timeOfDay: json['time_of_day'] as String, + + // Day 1 -> 7 !! Starting from Monday !! weekDay: json['week_day'] as int, + + // Line 1 or 2 tramLine: json['tram_line'] as int, + + // True -> Raml, False -> Victoria direction: json['direction'] as bool, ); } diff --git a/lib/arrival_fetch.dart b/lib/arrival_fetch.dart index e7bd392..2262d83 100644 --- a/lib/arrival_fetch.dart +++ b/lib/arrival_fetch.dart @@ -6,18 +6,16 @@ import 'package:witl/arrival.dart'; Future> fetchArrivals() async { try { + // Grabbing http reponse final response = await http.get(Uri.parse('http://141.144.238.26:48502/arrivals/all')); if (response.statusCode == 200) { - // List data = jsonDecode(response.body); - // List arrivals = List.from(data.map((dynamic arrivalJson) { - // return Arrival.fromJson(arrivalJson); - // })); + // Some JSON fuckery xd Iterable I = json.decode(response.body); List arrivals = List.from(I.map((model)=>Arrival.fromJson(model))); return arrivals.reversed.toList(); } else { - throw Exception('Failed to load Arrival'); + throw Exception('Failed to load Arrivals list'); } } catch (error) { throw Exception('Failed to fetch data: $error'); diff --git a/lib/arrival_post.dart b/lib/arrival_post.dart index eb5c6b7..7b8abca 100644 --- a/lib/arrival_post.dart +++ b/lib/arrival_post.dart @@ -4,11 +4,14 @@ import 'package:http/http.dart' as http; import 'package:witl/arrival.dart'; Future insertArrival(String date, int weekday, int line, bool direction) async { + // POST response as JSON final response = await http.post( Uri.parse('http://141.144.238.26:48502/arrivals/insert'), headers: { + // Headers used 'Content-Type': 'application/json; charset=UTF-8', }, + // Encoding a singular json entry body: jsonEncode( { 'time_of_day': date, 'week_day': weekday, diff --git a/lib/fetcher.dart b/lib/fetcher.dart index 002e8e4..d89dc4f 100644 --- a/lib/fetcher.dart +++ b/lib/fetcher.dart @@ -18,6 +18,7 @@ class _FetchAPIState extends State { appBar: AppBar( title: const Text("Fetching API"), actions: [ + // Refresh fetched list IconButton( onPressed: () { setState(() { @@ -26,10 +27,15 @@ class _FetchAPIState extends State { }, icon: const Icon(Icons.refresh_sharp), ), + + // Spacer const SizedBox(width: 30,), ], ), + // RefreshIndicator is used so that user can pull down + // in order to update instead of pressing the refresh button body: RefreshIndicator( + // Method to Use no argument parenthesis onRefresh: _refreshData, child: Column( mainAxisAlignment: MainAxisAlignment.start, @@ -41,13 +47,18 @@ class _FetchAPIState extends State { builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const CircularProgressIndicator(); - } else if (snapshot.hasError) { + } + else if (snapshot.hasError) { return Text('Failed to fetch data.\nError: ${snapshot.error}'); - } else { + } + else { return ListView.builder( + // List items to display itemCount: snapshot.data!.length, + // Building them itemBuilder: (context, index) { return ListTile( + // Really should be more informative about what's displayed title: Text("Arrival Time: ${snapshot.data![index].timeOfDay}"), titleAlignment: ListTileTitleAlignment.center, subtitle: Text("Week Day: ${weekNumToString(snapshot.data![index].weekDay)}"), @@ -64,8 +75,12 @@ class _FetchAPIState extends State { ), const SizedBox(height: 30,), InkWell( + // Navigating Home onTap: () { - Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false); + Navigator.pushNamedAndRemoveUntil( + context, + '/', + (route) => false); }, child: Container( padding: const EdgeInsets.all(20.0), @@ -81,6 +96,7 @@ class _FetchAPIState extends State { Future _refreshData() async { setState(() { + // Refresh arrivals list by invoking the fetch method fetchedArrivals = fetchArrivals(); }); } @@ -131,7 +147,7 @@ showArrivalInfo(BuildContext context, Arrival data) { ], ); - // show the dialog + // show the dialogue showDialog( context: context, builder: (BuildContext context) { diff --git a/lib/home_screen.dart b/lib/home_screen.dart index cad0885..12852ca 100644 --- a/lib/home_screen.dart +++ b/lib/home_screen.dart @@ -13,23 +13,32 @@ class HomeScreen extends StatelessWidget { title: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ + // Our Amazing Logo Image.asset('assets/images/choo.png', fit: BoxFit.contain, height: 64, ), + // Spacing const SizedBox(width: 10,), + // App Title const Text("WITL"), + // Fill out the area blankly + // So that the icon can be shoved far right const Expanded(child: SizedBox(),), + // Navigate to Settings IconButton( onPressed: () {Navigator.push( context, MaterialPageRoute(builder: (context) => const Settings()) );}, - icon: const Icon(Icons.settings)) + icon: const Icon(Icons.settings)), + + // Space from the end + const SizedBox(width: 30,), ] ), ), @@ -39,12 +48,15 @@ class HomeScreen extends StatelessWidget { const Row( mainAxisAlignment: MainAxisAlignment.center, children:[ + // Our Motto (?) Text("We may not be able to tell you why.\nBut surely are able to predict when."), ], ), + // Spacing const SizedBox(height: 80), + // To the fetching screen InkWell( onTap:() { Navigator.push( @@ -60,6 +72,7 @@ class HomeScreen extends StatelessWidget { const SizedBox(height: 30), + // To Data Input InkWell( onTap:() { Navigator.push( diff --git a/lib/input_data.dart b/lib/input_data.dart index c004027..e039c8f 100644 --- a/lib/input_data.dart +++ b/lib/input_data.dart @@ -159,7 +159,7 @@ class _InputDataState extends State { insertArrival('${now.hour}:${now.minute}:${now.second}', now.weekday, selectedLine, payloadDirection); //prompting of submission - showAlertDialog(context, selectedLine, selectedColor, selectedDirection, userFormattedString); + showSubmissionSuccess(context, selectedLine, selectedColor, selectedDirection, userFormattedString); }, child: Container(