Skip to content

Commit

Permalink
feat: vehicle number (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 authored Oct 23, 2024
1 parent 7fdec97 commit cb92c44
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class HomeScreenState extends State<HomeScreen> {
String? _selectedPurpose;
String? _otherPurposeText;

String? _vehicleNumber;

final List<String> _locations = [
'Gate A',
'Gate B',
Expand Down Expand Up @@ -168,8 +170,17 @@ class HomeScreenState extends State<HomeScreen> {
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(
Expand Down Expand Up @@ -266,7 +277,20 @@ class HomeScreenState extends State<HomeScreen> {
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,
),
),
],
),
),
Expand Down
20 changes: 20 additions & 0 deletions lib/services/database_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ class DatabaseService {
});
}

Future<String> 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<void> createRequest(
Expand Down

0 comments on commit cb92c44

Please sign in to comment.