45
lib/albut.dart
Normal file
45
lib/albut.dart
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
Future<Album> createAlbum(String title) async {
|
||||||
|
final response = await http.post(
|
||||||
|
Uri.parse('https://jsonplaceholder.typicode.com/albums'),
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
body: jsonEncode(<String, String>{
|
||||||
|
'title': title,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 201) {
|
||||||
|
// If the server did return a 201 CREATED response,
|
||||||
|
// then parse the JSON.
|
||||||
|
return Album.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||||
|
} else {
|
||||||
|
// If the server did not return a 201 CREATED response,
|
||||||
|
// then throw an exception.
|
||||||
|
throw Exception('Failed to create album.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Album {
|
||||||
|
final int id;
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
const Album({required this.id, required this.title});
|
||||||
|
|
||||||
|
factory Album.fromJson(Map<String, dynamic> json) {
|
||||||
|
return switch (json) {
|
||||||
|
{
|
||||||
|
'id': int id,
|
||||||
|
'title': String title,
|
||||||
|
} =>
|
||||||
|
Album(
|
||||||
|
id: id,
|
||||||
|
title: title,
|
||||||
|
),
|
||||||
|
_ => throw const FormatException('Failed to load album.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,24 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:witl/fetcher.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:witl/home_screen.dart';
|
|
||||||
|
|
||||||
class InputData extends StatelessWidget {
|
class InputData extends StatefulWidget {
|
||||||
const InputData({super.key});
|
const InputData({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_InputDataState createState() => _InputDataState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InputDataState extends State<InputData> {
|
||||||
|
late String selectedColor = 'Blue'; // Default color
|
||||||
|
late String selectedLine = '1'; // Default line
|
||||||
|
late String selectedDirection = 'Raml'; // Default Station Direction
|
||||||
|
|
||||||
|
// Date and Time Info, FULLY
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
|
||||||
|
// What will be displayed to the user
|
||||||
|
String userFormattedString = DateFormat('kk:mm EEE dd MMM').format(DateTime.now());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -12,35 +26,181 @@ class InputData extends StatelessWidget {
|
|||||||
title: const Text("Data Input"),
|
title: const Text("Data Input"),
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
const Text("Choose Tram Line and Colour"),
|
||||||
|
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
|
||||||
|
const Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text("Line:"),
|
||||||
|
SizedBox(width: 35),
|
||||||
|
Text("Colour:"),
|
||||||
|
SizedBox(width: 25),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
DropdownButton<String>(
|
||||||
|
value: selectedLine,
|
||||||
|
items: <String>['1', '2'].map((String value) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? newLine) {
|
||||||
|
setState(() {
|
||||||
|
selectedLine = newLine ?? '1'; // Set a default value if newLine is null
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 30),
|
||||||
|
DropdownButton<String>(
|
||||||
|
value: selectedColor,
|
||||||
|
items: <String>['Blue', 'Yellow'].map((String value) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? newCol) {
|
||||||
|
setState(() {
|
||||||
|
selectedColor = newCol ?? 'Blue'; // Set a default value if newCol is null
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
|
||||||
|
const Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text("Direction:"),
|
||||||
|
SizedBox(width: 20),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
DropdownButton<String>(
|
||||||
|
value: selectedDirection,
|
||||||
|
items: <String>['Raml', 'Victoria'].map((String value) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: (String? newEnd) {
|
||||||
|
setState(() {
|
||||||
|
selectedDirection = newEnd ?? 'Victoria'; // Set a default value if newLine is null
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
// Grab Data from Dropdowns
|
||||||
|
selectedColor; //
|
||||||
|
selectedLine;
|
||||||
|
|
||||||
|
// Conforming by db standard of boolean
|
||||||
|
bool payloadDirection;
|
||||||
|
|
||||||
|
if (selectedDirection == 'Raml') {
|
||||||
|
payloadDirection = true;
|
||||||
|
} else {
|
||||||
|
payloadDirection = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grab Time
|
||||||
|
now.weekday; // Day (1 -> 7) !! Starts Monday !!
|
||||||
|
now.hour; // Hour (0 -> 23)
|
||||||
|
now.minute; // Minute (0 -> 59)
|
||||||
|
now.second; // Second (0 -> 59)
|
||||||
|
|
||||||
|
// Send
|
||||||
|
//lingy plez
|
||||||
|
|
||||||
|
//prompting of submission
|
||||||
|
showAlertDialog(context, selectedLine, selectedColor, selectedDirection, userFormattedString);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: const Text("Submit Arrival"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 50),
|
||||||
|
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const HomeScreen())
|
'/',
|
||||||
|
(route) => false
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: const Text("To Homescreen")
|
child: const Text("Homescreen")),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const FetchAPI())
|
'/fetch',
|
||||||
|
(route) => false
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(20.0),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: const Text("To Fetch Data")
|
child: const Text("Fetch Data")),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showAlertDialog(BuildContext context, String chosenLine, String chosenColour, String chosenDir, String submissionDate) {
|
||||||
|
|
||||||
|
// set up the button
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("Pogchamp"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// set up the AlertDialog
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
title: const Text("Submitted (Cached?) Info"),
|
||||||
|
content: Text("Tram Colour: $chosenColour\n\nChosen Line: $chosenLine\n\nDirection: $chosenDir\n\nSubmitted On: $submissionDate"),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
// show the dialog
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:witl/fetcher.dart';
|
||||||
import 'package:witl/home_screen.dart';
|
import 'package:witl/home_screen.dart';
|
||||||
|
import 'package:witl/input_data.dart';
|
||||||
|
|
||||||
void main() => runApp(const MyApp());
|
void main() => runApp(const MyApp());
|
||||||
|
|
||||||
@@ -13,7 +15,22 @@ class MyApp extends StatelessWidget {
|
|||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.blue,
|
primarySwatch: Colors.blue,
|
||||||
),
|
),
|
||||||
home: const HomeScreen(),
|
|
||||||
|
// Navigashun with Routes
|
||||||
|
// Base "Home" Route
|
||||||
|
initialRoute: '/',
|
||||||
|
|
||||||
|
// Possible Routes
|
||||||
|
routes: {
|
||||||
|
// Homescreen
|
||||||
|
'/': (context) => const HomeScreen(),
|
||||||
|
|
||||||
|
// Fetching API Data
|
||||||
|
'/fetch': (context) => const FetchAPI(),
|
||||||
|
|
||||||
|
// User Input
|
||||||
|
'/input': (context) => const InputData(),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
pubspec.lock
40
pubspec.lock
@@ -66,23 +66,47 @@ packages:
|
|||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: flutter_lints
|
name: flutter_lints
|
||||||
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
|
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "3.0.1"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
http:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: http
|
||||||
|
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.2"
|
||||||
|
http_parser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: http_parser
|
||||||
|
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.2"
|
||||||
|
intl:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: intl
|
||||||
|
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.19.0"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: lints
|
name: lints
|
||||||
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
|
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "3.0.0"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -168,6 +192,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.1"
|
version: "0.6.1"
|
||||||
|
typed_data:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: typed_data
|
||||||
|
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.2"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
|
intl: ^0.19.0
|
||||||
|
http: ^1.1.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
@@ -45,7 +47,7 @@ dev_dependencies:
|
|||||||
# activated in the `analysis_options.yaml` file located at the root of your
|
# activated in the `analysis_options.yaml` file located at the root of your
|
||||||
# package. See that file for information about deactivating specific lint
|
# package. See that file for information about deactivating specific lint
|
||||||
# rules and activating additional ones.
|
# rules and activating additional ones.
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^3.0.1
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|||||||
Reference in New Issue
Block a user