issues fixes
This commit is contained in:
parent
e00b27f994
commit
5238e245f4
@ -196,23 +196,26 @@ class DepartmentDataState extends State<DepartmentData> {
|
|||||||
? await http.put(uri, headers: headers, body: body)
|
? await http.put(uri, headers: headers, body: body)
|
||||||
: await http.post(uri, headers: headers, body: body);
|
: await http.post(uri, headers: headers, body: body);
|
||||||
|
|
||||||
switch (response.statusCode) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
case 200:
|
print("successfully!");
|
||||||
print("Update - Response: ${response.body}");
|
print("Response: ${response.body}");
|
||||||
_clearError();
|
_clearError();
|
||||||
widget.fetchGetDepartment();
|
widget.fetchGetDepartment();
|
||||||
|
// dispose();
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
break;
|
} else if (response.statusCode == 404) {
|
||||||
|
|
||||||
case 201:
|
|
||||||
print("Save - Response: ${response.body}");
|
|
||||||
_clearError();
|
|
||||||
await widget.fetchGetDepartment();
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
break;
|
final message = jsonDecode(response.body)['message'] ?? 'Unknown error';
|
||||||
|
|
||||||
default:
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
print("Failed to submit department. Status: ${response.statusCode}");
|
SnackBar(
|
||||||
|
content: Text(message),
|
||||||
|
backgroundColor: Colors.redAccent,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
print("Failed to submit. Status: ${response.statusCode}");
|
||||||
print("Error: ${response.body}");
|
print("Error: ${response.body}");
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -384,7 +384,37 @@ class _BusScreenState extends State<BusScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
||||||
|
// Parse the selected date
|
||||||
|
final dateText = _dateController.text ?? "";
|
||||||
|
final selectedDate = DateFormat(
|
||||||
|
'dd-MM-yyyy',
|
||||||
|
).parse(dateText); // or 'yyyy-MM-dd' depending on your format
|
||||||
|
final now = DateTime.now();
|
||||||
|
|
||||||
|
final selectedDateTime = DateTime(
|
||||||
|
selectedDate.year,
|
||||||
|
selectedDate.month,
|
||||||
|
selectedDate.day,
|
||||||
|
pickedTime.hour,
|
||||||
|
pickedTime.minute,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
final isToday =
|
||||||
|
selectedDate.year == now.year &&
|
||||||
|
selectedDate.month == now.month &&
|
||||||
|
selectedDate.day == now.day;
|
||||||
|
|
||||||
|
bool isPastTime = selectedDateTime.isBefore(now);
|
||||||
|
|
||||||
|
if (isToday && isPastTime) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
errorMessages["time"] = "You can't select a past time.";
|
||||||
|
_selectedCheckOutTime = null; // ✅ Reset time variable
|
||||||
|
_timeController.text = ""; // ✅ Clear text field
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}else{ setState(() {
|
||||||
_selectedCheckOutTime = pickedTime;
|
_selectedCheckOutTime = pickedTime;
|
||||||
// Formatting time to HH:mm (24-hour format)
|
// Formatting time to HH:mm (24-hour format)
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@ -393,7 +423,7 @@ class _BusScreenState extends State<BusScreen> {
|
|||||||
pickedTime.minute),
|
pickedTime.minute),
|
||||||
);
|
);
|
||||||
_timeController.text = formattedTime;
|
_timeController.text = formattedTime;
|
||||||
});
|
}); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +610,7 @@ class _BusScreenState extends State<BusScreen> {
|
|||||||
if (errorMessages["time"] != null) ...[
|
if (errorMessages["time"] != null) ...[
|
||||||
SizedBox(height: 5), // Space before error message
|
SizedBox(height: 5), // Space before error message
|
||||||
Text(
|
Text(
|
||||||
"Required",
|
errorMessages["time"]!,
|
||||||
style: TextStyle(color: Colors.red, fontSize: 12),
|
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -501,24 +501,75 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
||||||
|
// Parse the selected date
|
||||||
|
final dateText = _dateController.text ?? "";
|
||||||
|
final selectedDate = DateFormat(
|
||||||
|
'dd-MM-yyyy',
|
||||||
|
).parse(dateText); // or 'yyyy-MM-dd' depending on your format
|
||||||
|
final now = DateTime.now();
|
||||||
|
|
||||||
|
final selectedDateTime = DateTime(
|
||||||
|
selectedDate.year,
|
||||||
|
selectedDate.month,
|
||||||
|
selectedDate.day,
|
||||||
|
pickedTime.hour,
|
||||||
|
pickedTime.minute,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
final isToday =
|
||||||
|
selectedDate.year == now.year &&
|
||||||
|
selectedDate.month == now.month &&
|
||||||
|
selectedDate.day == now.day;
|
||||||
|
|
||||||
|
bool isPastTime = selectedDateTime.isBefore(now);
|
||||||
|
|
||||||
|
if (isToday && isPastTime) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
errorMessages["time"] = "You can't select a past time.";
|
||||||
|
_selectedCheckOutTime = null; // ✅ Reset time variable
|
||||||
|
_timeController.text = ""; // ✅ Clear text field
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}else{ setState(() {
|
||||||
_selectedCheckOutTime = pickedTime;
|
_selectedCheckOutTime = pickedTime;
|
||||||
// Formatting time to HH:mm (24-hour format)
|
// Formatting time to HH:mm (24-hour format)
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final formattedTime = DateFormat('HH:mm').format(
|
final formattedTime = DateFormat('HH:mm').format(
|
||||||
DateTime(
|
DateTime(now.year, now.month, now.day, pickedTime.hour,
|
||||||
now.year,
|
pickedTime.minute),
|
||||||
now.month,
|
|
||||||
now.day,
|
|
||||||
pickedTime.hour,
|
|
||||||
pickedTime.minute,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
errorMessages["time"] = "";
|
||||||
_timeController.text = formattedTime;
|
_timeController.text = formattedTime;
|
||||||
});
|
}); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Future<void> _selectCheckOutTime(BuildContext context) async {
|
||||||
|
// TimeOfDay? pickedTime = await showTimePicker(
|
||||||
|
// context: context,
|
||||||
|
// initialTime: _selectedCheckOutTime ?? TimeOfDay.now(),
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
||||||
|
// setState(() {
|
||||||
|
// _selectedCheckOutTime = pickedTime;
|
||||||
|
// // Formatting time to HH:mm (24-hour format)
|
||||||
|
// final now = DateTime.now();
|
||||||
|
// final formattedTime = DateFormat('HH:mm').format(
|
||||||
|
// DateTime(
|
||||||
|
// now.year,
|
||||||
|
// now.month,
|
||||||
|
// now.day,
|
||||||
|
// pickedTime.hour,
|
||||||
|
// pickedTime.minute,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// _timeController.text = formattedTime;
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@ -687,7 +738,8 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
|||||||
),
|
),
|
||||||
if (errorMessages["time"] != null) ...[
|
if (errorMessages["time"] != null) ...[
|
||||||
SizedBox(height: 5), // Space before error message
|
SizedBox(height: 5), // Space before error message
|
||||||
Text("Required", style: TextStyle(color: Colors.red, fontSize: 12)),
|
// Text("Required", style: TextStyle(color: Colors.red, fontSize: 12)),
|
||||||
|
Text(errorMessages["time"]!, style: TextStyle(color: Colors.red, fontSize: 12)),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user