Quantified Payload Items (Sending not implemented yet)

This commit is contained in:
2023-12-26 17:36:46 +02:00
parent 1eabbaa00e
commit f7a6dbf8ac
4 changed files with 122 additions and 6 deletions

45
lib/albut.dart Normal file
View 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.'),
};
}
}

View File

@@ -11,9 +11,13 @@ class InputData extends StatefulWidget {
class _InputDataState extends State<InputData> { class _InputDataState extends State<InputData> {
late String selectedColor = 'Blue'; // Default color late String selectedColor = 'Blue'; // Default color
late String selectedLine = '1'; // Default line late String selectedLine = '1'; // Default line
late String selectedDirection = 'Raml'; // Default Station Direction
// Date and Time Info, FULLY
DateTime now = DateTime.now(); DateTime now = DateTime.now();
String formattedDate = DateFormat('kk:mm:ss \n EEE d MMM').format(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) {
@@ -75,20 +79,62 @@ class _InputDataState extends State<InputData> {
const SizedBox(height: 30), 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: () {
// Grab Data from Dropdowns // Grab Data from Dropdowns
selectedColor; selectedColor; //
selectedLine; selectedLine;
// Conforming by db standard of boolean
bool payloadDirection;
if (selectedDirection == 'Raml') {
payloadDirection = true;
} else {
payloadDirection = false;
}
// Grab Time // Grab Time
formattedDate; now.weekday; // Day (1 -> 7) !! Starts Monday !!
now.hour; // Hour (0 -> 23)
now.minute; // Minute (0 -> 59)
now.second; // Second (0 -> 59)
// Send // Send
//lingy plez //lingy plez
//prompting of submission //prompting of submission
showAlertDialog(context, selectedLine, selectedColor, formattedDate); showAlertDialog(context, selectedLine, selectedColor, selectedDirection, userFormattedString);
}, },
child: Container( child: Container(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
@@ -131,7 +177,7 @@ class _InputDataState extends State<InputData> {
} }
} }
showAlertDialog(BuildContext context, String chosenLine, String chosenColour, String submissionDate) { showAlertDialog(BuildContext context, String chosenLine, String chosenColour, String chosenDir, String submissionDate) {
// set up the button // set up the button
Widget okButton = TextButton( Widget okButton = TextButton(
@@ -144,7 +190,7 @@ showAlertDialog(BuildContext context, String chosenLine, String chosenColour, St
// set up the AlertDialog // set up the AlertDialog
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: const Text("Submitted (Cached?) Info"), title: const Text("Submitted (Cached?) Info"),
content: Text("Tram Colour: $chosenColour\nChosen Line: $chosenLine\nSubmitted On:\n$submissionDate"), content: Text("Tram Colour: $chosenColour\n\nChosen Line: $chosenLine\n\nDirection: $chosenDir\n\nSubmitted On: $submissionDate"),
actions: [ actions: [
okButton, okButton,
], ],

View File

@@ -75,6 +75,22 @@ packages:
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: intl:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -176,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:

View File

@@ -36,6 +36,7 @@ dependencies:
# 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 intl: ^0.19.0
http: ^1.1.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: