TimeTracker/lib/pages/HomePage.dart

203 lines
6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:libac_dart/utils/TimeUtils.dart';
import 'package:libacflutter/Constants.dart';
import 'package:libacflutter/Prompt.dart';
import 'package:timetrack/consts.dart';
import 'package:timetrack/data.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<StatefulWidget> createState() {
return _HomePageState();
}
}
class _HomePageState extends State<HomePage> {
@override
void didChangeDependencies() {
setState(() {});
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Time Tracker"),
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
),
drawer: Drawer(
elevation: 8,
child: SingleChildScrollView(
child: Column(
children: [
DrawerHeader(
child: Column(
children: [
Text("Time Tracker"),
Text("Created by Tara Piccari"),
Text("Copyright 2025 - Present"),
Text("Version: ${TTConsts.VERSION}"),
],
),
),
ListTile(
title: Text("Update Settings.."),
subtitle: Text(
"Open the update settings. Channel, check for updates, and installation",
),
onTap: () async {
await Navigator.pushNamed(context, "/upd");
setState(() {});
},
leading: Icon(Icons.update),
),
ListTile(
title: Text("RESET APP SESSION"),
onTap: () async {
setState(() {
SessionData.IsOnTheClock = false;
SessionData.StartTime = 0;
SessionData.Trips = [];
SessionData.currentDelivery = null;
SessionData.currentTrip = null;
});
},
),
],
),
),
),
body: SingleChildScrollView(
child: Column(
children: [
if (!SessionData.IsOnTheClock)
Center(
child: ElevatedButton(
onPressed: () async {
setState(() {
SessionData.Login();
});
},
child: Text("ENGAGE"),
),
),
if (SessionData.IsOnTheClock) GetLoggedInWidgets(),
],
),
),
);
}
Widget GetTripWidgets() {
return Column(
children: [
Text(
"Trip started; Base Pay: \$${SessionData.currentTrip!.BasePay}",
style: TextStyle(fontSize: 18),
),
Text(
"To end both your current delivery, and the trip, tap on END TRIP",
style: TextStyle(fontSize: 18),
),
Text(
"You are currently on Delivery #${SessionData.currentTrip!.deliveries.length}",
),
ElevatedButton(
onPressed: () async {
var reply = await showDialog(
context: context,
builder: (bld) {
return InputPrompt(
title: "What was the tip?",
prompt: "If there was no tip, enter a 0, or just hit submit.",
type: InputPromptType.Number,
);
},
);
if (reply == null || reply == "") reply = "0";
double tip = double.parse(reply as String);
SessionData.currentDelivery!.TipAmount = tip;
SessionData.currentDelivery!.MarkEndLocation();
SessionData.EndTrip();
setState(() {});
},
child: Text("END TRIP"),
),
],
);
}
Widget GetDeliveryWidgets() {
return Column(
children: [
ElevatedButton(
onPressed: () async {
var reply = await showDialog(
context: context,
builder: (bld) {
return InputPrompt(
title: "What was the tip?",
prompt:
"If there was no tip, enter a 0, or hit submit and leave blank",
type: InputPromptType.Number,
);
},
);
if (reply == null || reply == "") reply = "0";
double tip = double.parse(reply as String);
SessionData.currentDelivery!.TipAmount = tip;
SessionData.currentDelivery!.MarkEndLocation();
SessionData.GetNewDelivery();
setState(() {});
},
child: Text("Start new delivery"),
),
],
);
}
Widget GetLoggedInWidgets() {
return Column(
children: [
Text(
"You are now on the clock\nYour location is being tracked for record keeping purposes.\n\nYou started at ${SessionData.StartTimeAsDateTime}\n\n",
style: TextStyle(fontSize: 18),
),
if (SessionData.currentTrip != null) GetTripWidgets(),
if (SessionData.currentDelivery != null) GetDeliveryWidgets(),
if (SessionData.currentTrip == null)
ElevatedButton(
onPressed: () async {
var reply = await showDialog(
context: context,
builder: (builder) {
return InputPrompt(
title: "What is the base pay?",
prompt: "Enter the base pay amount below.",
type: InputPromptType.Number,
);
},
);
if (reply == null || reply == "") reply = "0";
double basePay = double.parse(reply as String);
SessionData.GetNewTrip(basePay: basePay);
SessionData.GetNewDelivery();
setState(() {});
},
child: Text("Start New Trip"),
),
],
);
}
}