diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 2be39cf..0dc0e13 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -45,6 +45,8 @@ class HomeScreenState extends State { String? _selectedPurpose; String? _otherPurposeText; + String? _vehicleNumber; + final List _locations = [ 'Gate A', 'Gate B', @@ -168,8 +170,17 @@ class HomeScreenState extends State { final requestData = snapshot.data; final requestStatus = requestData?['status'] ?? 'No recent request found'; + final requestId = requestData?['requestId']; final canSubmit = requestStatus != 'pending'; + if (requestStatus == 'approved' && requestId != null) { + _databaseService.getVehicleNumber(requestId).then((vehicleNumber) { + setState(() { + _vehicleNumber = vehicleNumber; + }); + }); + } + // Add cancel button logic if (requestStatus == 'pending' || requestStatus == 'approved') { Widget _ = ElevatedButton( @@ -266,7 +277,20 @@ class HomeScreenState extends State { onPressed: () => cancelRequest(), child: const Text('Cancel Request'), ), - ) + ), + if (requestStatus == 'approved') + Padding( + padding: const EdgeInsets.only(top: 10), + child: Text( + 'Vehicle Number: ${_vehicleNumber ?? 'Loading...'}', + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + textAlign: TextAlign.center, + ), + ), ], ), ), diff --git a/lib/services/database_service.dart b/lib/services/database_service.dart index b370c08..1a3fcd3 100644 --- a/lib/services/database_service.dart +++ b/lib/services/database_service.dart @@ -35,6 +35,27 @@ class DatabaseService { }); } + Future getVehicleNumber(String documentId) async { + try { + DocumentSnapshot docSnapshot = await FirebaseFirestore.instance + .collection('bookings') + .doc(documentId) + .get(); + + if (docSnapshot.exists) { + String vehicleNumber = docSnapshot.get('vehicleNumber'); + return vehicleNumber; + } else { + print('Error document does not exist'); + return 'Error'; + } + } catch (e) { + print('Error getting document: $e'); + return 'Error'; + } + } + + final FirebaseFirestore _db = FirebaseFirestore.instance; Future createRequest(