Merge branch 'main' of bitbucket.org:venbainformationtechnology/ts-tat
This commit is contained in:
commit
20a24c7d46
@ -196,24 +196,27 @@ class DepartmentDataState extends State<DepartmentData> {
|
||||
? await http.put(uri, headers: headers, body: body)
|
||||
: await http.post(uri, headers: headers, body: body);
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
print("Update - Response: ${response.body}");
|
||||
_clearError();
|
||||
widget.fetchGetDepartment();
|
||||
Navigator.of(context).pop();
|
||||
break;
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
print("successfully!");
|
||||
print("Response: ${response.body}");
|
||||
_clearError();
|
||||
widget.fetchGetDepartment();
|
||||
// dispose();
|
||||
Navigator.of(context).pop();
|
||||
} else if (response.statusCode == 404) {
|
||||
Navigator.of(context).pop();
|
||||
final message = jsonDecode(response.body)['message'] ?? 'Unknown error';
|
||||
|
||||
case 201:
|
||||
print("Save - Response: ${response.body}");
|
||||
_clearError();
|
||||
await widget.fetchGetDepartment();
|
||||
Navigator.of(context).pop();
|
||||
break;
|
||||
|
||||
default:
|
||||
print("Failed to submit department. Status: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: Colors.redAccent,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print("Failed to submit. Status: ${response.statusCode}");
|
||||
print("Error: ${response.body}");
|
||||
}
|
||||
} catch (e) {
|
||||
print(" Error submitting plan: $e");
|
||||
|
||||
@ -384,7 +384,37 @@ class _BusScreenState extends State<BusScreen> {
|
||||
);
|
||||
|
||||
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
||||
setState(() {
|
||||
// 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(() {
|
||||
errorMessages["time"] = "You can't select a past time.";
|
||||
_selectedCheckOutTime = null; // ✅ Reset time variable
|
||||
_timeController.text = ""; // ✅ Clear text field
|
||||
});
|
||||
return;
|
||||
}else{ setState(() {
|
||||
_selectedCheckOutTime = pickedTime;
|
||||
// Formatting time to HH:mm (24-hour format)
|
||||
final now = DateTime.now();
|
||||
@ -393,7 +423,7 @@ class _BusScreenState extends State<BusScreen> {
|
||||
pickedTime.minute),
|
||||
);
|
||||
_timeController.text = formattedTime;
|
||||
});
|
||||
}); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -580,7 +610,7 @@ class _BusScreenState extends State<BusScreen> {
|
||||
if (errorMessages["time"] != null) ...[
|
||||
SizedBox(height: 5), // Space before error message
|
||||
Text(
|
||||
"Required",
|
||||
errorMessages["time"]!,
|
||||
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||
),
|
||||
],
|
||||
|
||||
@ -99,7 +99,7 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
|
||||
_addFocusListener(
|
||||
_destinationFocusNode,
|
||||
(focus) => _destinationFocus = focus,
|
||||
(focus) => _destinationFocus = focus,
|
||||
);
|
||||
_addFocusListener(_locationFocusNode, (focus) => _locationFocus = focus);
|
||||
_addFocusListener(_dateFocusNode, (focus) => _dateFocus = focus);
|
||||
@ -107,7 +107,7 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
_addFocusListener(_taxiReqFocusNode, (focus) => _taxiReqFocused = focus);
|
||||
_addFocusListener(
|
||||
_numPassengerFocusNode,
|
||||
(focus) => _numPassengerFocus = focus,
|
||||
(focus) => _numPassengerFocus = focus,
|
||||
);
|
||||
_addFocusListener(_commentsFocusNode, (focus) => _commentsFocus = focus);
|
||||
|
||||
@ -262,14 +262,14 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
List<dynamic> purposeList = widget.apiData?['taxt_car_type'] ?? [];
|
||||
|
||||
List<DropdownMenuItem<String>> dropdownItems =
|
||||
purposeList
|
||||
.map(
|
||||
(item) => DropdownMenuItem<String>(
|
||||
value: item['dropdown_key'],
|
||||
child: Text(item['dropdown_value']),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
purposeList
|
||||
.map(
|
||||
(item) => DropdownMenuItem<String>(
|
||||
value: item['dropdown_key'],
|
||||
child: Text(item['dropdown_value']),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
if (dropdownItems.isEmpty) {
|
||||
dropdownItems.add(
|
||||
@ -285,7 +285,7 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
|
||||
// Default selected value
|
||||
selectedCarType ??=
|
||||
dropdownItems.isNotEmpty ? dropdownItems.first.value : null;
|
||||
dropdownItems.isNotEmpty ? dropdownItems.first.value : null;
|
||||
|
||||
return [
|
||||
Column(
|
||||
@ -378,16 +378,16 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
), // Proper padding
|
||||
),
|
||||
onChanged:
|
||||
purposeList.isNotEmpty
|
||||
? (newValue) {
|
||||
setState(() {
|
||||
selectedCarType = newValue;
|
||||
});
|
||||
print(
|
||||
"Updating form data: Flight -> trip_type -> ${newValue ?? ""}",
|
||||
);
|
||||
}
|
||||
: null,
|
||||
purposeList.isNotEmpty
|
||||
? (newValue) {
|
||||
setState(() {
|
||||
selectedCarType = newValue;
|
||||
});
|
||||
print(
|
||||
"Updating form data: Flight -> trip_type -> ${newValue ?? ""}",
|
||||
);
|
||||
}
|
||||
: null,
|
||||
|
||||
items: dropdownItems,
|
||||
),
|
||||
@ -403,14 +403,14 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
List<dynamic> purposeList = widget.apiData?['taxi_car_required_for'] ?? [];
|
||||
|
||||
List<DropdownMenuItem<String>> dropdownItems =
|
||||
purposeList
|
||||
.map(
|
||||
(item) => DropdownMenuItem<String>(
|
||||
value: item['dropdown_key'],
|
||||
child: Text(item['dropdown_value']),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
purposeList
|
||||
.map(
|
||||
(item) => DropdownMenuItem<String>(
|
||||
value: item['dropdown_key'],
|
||||
child: Text(item['dropdown_value']),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
|
||||
if (dropdownItems.isEmpty) {
|
||||
dropdownItems.add(
|
||||
@ -426,16 +426,16 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
|
||||
// Default selected value
|
||||
selectedReqTaxi ??=
|
||||
dropdownItems.isNotEmpty ? dropdownItems.first.value : null;
|
||||
dropdownItems.isNotEmpty ? dropdownItems.first.value : null;
|
||||
|
||||
return [
|
||||
CustomTextFieldWrapper(
|
||||
isFocused: _taxiReqFocused,
|
||||
isDesktop: isDesktop,
|
||||
width:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.34
|
||||
: MediaQuery.of(context).size.width * 0.66,
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.34
|
||||
: MediaQuery.of(context).size.width * 0.66,
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: DropdownButtonFormField<String>(
|
||||
@ -449,16 +449,16 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
), // Proper padding
|
||||
),
|
||||
onChanged:
|
||||
purposeList.isNotEmpty
|
||||
? (newValue) {
|
||||
setState(() {
|
||||
selectedReqTaxi = newValue;
|
||||
});
|
||||
print(
|
||||
"Updating form data: Flight -> trip_type -> ${newValue ?? ""}",
|
||||
);
|
||||
}
|
||||
: null,
|
||||
purposeList.isNotEmpty
|
||||
? (newValue) {
|
||||
setState(() {
|
||||
selectedReqTaxi = newValue;
|
||||
});
|
||||
print(
|
||||
"Updating form data: Flight -> trip_type -> ${newValue ?? ""}",
|
||||
);
|
||||
}
|
||||
: null,
|
||||
|
||||
items: dropdownItems,
|
||||
),
|
||||
@ -478,10 +478,10 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate:
|
||||
_selectedCheckOutDate != null &&
|
||||
_selectedCheckOutDate!.isAfter(today)
|
||||
? _selectedCheckOutDate!
|
||||
: today,
|
||||
_selectedCheckOutDate != null &&
|
||||
_selectedCheckOutDate!.isAfter(today)
|
||||
? _selectedCheckOutDate!
|
||||
: today,
|
||||
firstDate: today,
|
||||
lastDate: DateTime(2100),
|
||||
);
|
||||
@ -501,24 +501,75 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
);
|
||||
|
||||
if (pickedTime != null && pickedTime != _selectedCheckOutTime) {
|
||||
setState(() {
|
||||
// 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(() {
|
||||
errorMessages["time"] = "You can't select a past time.";
|
||||
_selectedCheckOutTime = null; // ✅ Reset time variable
|
||||
_timeController.text = ""; // ✅ Clear text field
|
||||
});
|
||||
return;
|
||||
}else{ 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,
|
||||
),
|
||||
DateTime(now.year, now.month, now.day, pickedTime.hour,
|
||||
pickedTime.minute),
|
||||
);
|
||||
errorMessages["time"] = "";
|
||||
_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 [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -687,7 +738,8 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
),
|
||||
if (errorMessages["time"] != null) ...[
|
||||
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)),
|
||||
],
|
||||
],
|
||||
),
|
||||
@ -712,9 +764,9 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
isFocused: _commentsFocus, // Dropdown doesn't use focus
|
||||
isDesktop: isDesktop,
|
||||
width:
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.34
|
||||
: MediaQuery.of(context).size.width * 0.66,
|
||||
isDesktop
|
||||
? MediaQuery.of(context).size.width * 0.34
|
||||
: MediaQuery.of(context).size.width * 0.66,
|
||||
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
@ -782,4 +834,4 @@ class _TaxiScreenState extends State<TaxiScreen> {
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user