import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:libacflutter/Constants.dart'; import 'package:timetrack/consts.dart'; import 'package:timetrack/data.dart'; class WebMain extends StatefulWidget { @override State createState() { return _WebMain(); } } class _WebMain extends State { TextEditingController sessionIDController = TextEditingController(); @override void didChangeDependencies() { sessionIDController.text = SessionData.LastSessionID; 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}"), ], ), ), if (SessionData.IsReadOnly) 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"); }, ), if (SessionData.IsReadOnly) ListTile( title: Text("Work Data"), subtitle: Text("View work data"), leading: Icon(Icons.work_history), onTap: () async { // Open up the work data viewer and editor. // Edit will be disabled for web or read only mode. await Navigator.pushNamed(context, "/work"); setState(() {}); }, ), ], ), ), ), body: Padding( padding: EdgeInsets.all(8), child: SingleChildScrollView( child: Column( children: [ // Start doing magic! if (SessionData.DisplayError.isNotEmpty) Text(SessionData.DisplayError, style: TextStyle(fontSize: 18)), // Check what widgets need to be displayed. if (SessionData.IsReadOnly) GetReadOnlyWidgets(), if (!SessionData.IsReadOnly) GetLoadWidgets(), ], ), ), ), ); } Widget GetReadOnlyWidgets() { return Column( children: [ Text( "Use the top left menu to show the various pages for the data viewer.", ), ElevatedButton( onPressed: () async { SessionData.IsReadOnly = false; SessionData.Trips = []; SessionData.positions = []; SessionData.DisplayError = ""; }, child: Text("Close Session"), ), ], ); } Widget GetLoadWidgets() { return Column( children: [ // Present a text box for the session ID, and a button for loading. ListTile(title: Text("Session ID")), TextField( controller: sessionIDController, decoration: InputDecoration(border: OutlineInputBorder()), ), ElevatedButton( onPressed: () async { await SessionData.DownloadData(); setState(() {}); }, child: Text("Load Session", style: TextStyle(fontSize: 18)), ), ], ); } }