Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vehicle number #1

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading