Some comments never hurt anyone
This commit is contained in:
@@ -9,7 +9,7 @@ class Settings extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _Settings extends State<Settings> {
|
||||
late String selectedTheme = 'Dark';
|
||||
late String selectedTheme = 'Dark'; // Default app theme
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -20,9 +20,12 @@ class _Settings extends State<Settings> {
|
||||
|
||||
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<String> (
|
||||
value: selectedTheme,
|
||||
items: <String>["Light", "Dark", "System Default"].map((String value) {
|
||||
@@ -31,6 +34,7 @@ class _Settings extends State<Settings> {
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
// Updating Selection
|
||||
onChanged: (String? updatedTheme) {
|
||||
setState(() {
|
||||
selectedTheme = updatedTheme ?? selectedTheme;
|
||||
|
||||
@@ -13,9 +13,16 @@ class Arrival {
|
||||
|
||||
factory Arrival.fromJson(Map<String, dynamic> 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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,18 +6,16 @@ import 'package:witl/arrival.dart';
|
||||
|
||||
Future<List<Arrival>> 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<dynamic> data = jsonDecode(response.body);
|
||||
// List<Arrival> arrivals = List<Arrival>.from(data.map((dynamic arrivalJson) {
|
||||
// return Arrival.fromJson(arrivalJson);
|
||||
// }));
|
||||
// Some JSON fuckery xd
|
||||
Iterable I = json.decode(response.body);
|
||||
List<Arrival> arrivals = List<Arrival>.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');
|
||||
|
||||
@@ -4,11 +4,14 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:witl/arrival.dart';
|
||||
|
||||
Future<Arrival> 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: <String, String> {
|
||||
// Headers used
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
// Encoding a singular json entry
|
||||
body: jsonEncode(<String, dynamic> {
|
||||
'time_of_day': date,
|
||||
'week_day': weekday,
|
||||
|
||||
@@ -18,6 +18,7 @@ class _FetchAPIState extends State<FetchAPI> {
|
||||
appBar: AppBar(
|
||||
title: const Text("Fetching API"),
|
||||
actions: [
|
||||
// Refresh fetched list
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
@@ -26,10 +27,15 @@ class _FetchAPIState extends State<FetchAPI> {
|
||||
},
|
||||
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<FetchAPI> {
|
||||
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<FetchAPI> {
|
||||
),
|
||||
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<FetchAPI> {
|
||||
|
||||
Future<void> _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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -159,7 +159,7 @@ class _InputDataState extends State<InputData> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user