import 'package:flutter/material.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 createState() { return _HomePageState(); } } class _HomePageState extends State { @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("Trip Map"), leading: Icon(Icons.map), subtitle: Text( "View a map of the route\n(NOTE: This is not live, and reflects the current state as of the time the map is opened.)", ), onTap: () async { await Navigator.pushNamed(context, "/map"); }, ), 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: [ Text( "Hit engage when you are ready to go online and start tracking location data, and trips.", style: TextStyle(fontSize: 18), ), 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 GetNonTripWidgets() { return Column( children: [ 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"), ), ElevatedButton( onPressed: () async { if (SessionData.currentTrip != null || SessionData.currentDelivery != null) { showDialog( context: context, builder: (build) { return AlertDialog( title: Text("Cannot end work day"), content: Text( "You must end the trip and any delivery before you can fully end the work day.", ), ); }, ); } else { SessionData.Logout(); setState(() {}); } }, child: Text("End work day"), ), ], ); } 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) GetNonTripWidgets(), ], ); } }