validation changes
This commit is contained in:
parent
f1c153162b
commit
e8eaad1a1f
@ -1089,8 +1089,9 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
SizedBox(height: 5), // Space before error message
|
||||
Text(
|
||||
errorMessages["end_date"]!,
|
||||
// "Select End Date",
|
||||
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||
style: const TextStyle(color: Colors.red, fontSize: 12),
|
||||
maxLines: 2, // Allow it to wrap onto two lines
|
||||
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@ -38,20 +38,21 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
|
||||
final FocusNode _tripTypeFocusNode = FocusNode();
|
||||
final FocusNode _hotelNameFocusNode = FocusNode();
|
||||
final FocusNode _fromFocusNode = FocusNode();
|
||||
final FocusNode _dateFocusNode = FocusNode();
|
||||
final FocusNode _startDateFocusNode = FocusNode();
|
||||
final FocusNode _endDateFocusNode = FocusNode();
|
||||
final FocusNode _commentsFocusNode = FocusNode();
|
||||
final FocusNode _nomineeFocusNode = FocusNode();
|
||||
|
||||
late TextEditingController _tripTypeController = TextEditingController();
|
||||
late TextEditingController _startdateController = TextEditingController();
|
||||
late TextEditingController _startDateController = TextEditingController();
|
||||
late TextEditingController _endDateController = TextEditingController();
|
||||
late TextEditingController _insuranceCommentsController =
|
||||
TextEditingController();
|
||||
late TextEditingController _nomineeController = TextEditingController();
|
||||
|
||||
bool _isHotelNameFocused = false;
|
||||
bool _dateFocus = false;
|
||||
bool _startDateFocus = false;
|
||||
bool _endDateFocus = false;
|
||||
bool _commentsFocus = false;
|
||||
bool _nomineeFocus = false;
|
||||
|
||||
@ -63,7 +64,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
Map<String, dynamic> get InsuranceData {
|
||||
Map<String, dynamic> data = {
|
||||
"type_of_insurance": selectedInsuranceType,
|
||||
"start_date": _startdateController.text,
|
||||
"start_date": _startDateController.text,
|
||||
"end_date": _endDateController.text,
|
||||
"comments": _insuranceCommentsController.text,
|
||||
"nominee_name": _nomineeController.text,
|
||||
@ -93,9 +94,14 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
_isHotelNameFocused = _hotelNameFocusNode.hasFocus;
|
||||
});
|
||||
});
|
||||
_dateFocusNode.addListener(() {
|
||||
_endDateFocusNode.addListener(() {
|
||||
setState(() {
|
||||
_dateFocus = _fromFocusNode.hasFocus;
|
||||
_endDateFocus = _endDateFocusNode.hasFocus;
|
||||
});
|
||||
});
|
||||
_startDateFocusNode.addListener(() {
|
||||
setState(() {
|
||||
_startDateFocus = _startDateFocusNode.hasFocus;
|
||||
});
|
||||
});
|
||||
_commentsFocusNode.addListener(() {
|
||||
@ -113,7 +119,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
_insuranceCommentsController = TextEditingController(
|
||||
text: widget.selectedItem?["comments"] ?? "",
|
||||
);
|
||||
_startdateController = TextEditingController(
|
||||
_startDateController = TextEditingController(
|
||||
text: widget.selectedItem?["start_date"] ?? "",
|
||||
);
|
||||
_endDateController = TextEditingController(
|
||||
@ -141,26 +147,15 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
// ✅ Only set controller after value is updated
|
||||
// final parsedDate =
|
||||
// DateTime.tryParse(flightFirstTripDateNotifier.value ?? '');
|
||||
final parsedDate = DateFormat(
|
||||
"dd-MM-yyyy",
|
||||
).parse(flightFirstTripDateNotifier.value ?? '');
|
||||
if (parsedDate != null) {
|
||||
_startdateController.text = DateFormat('dd-MM-yyyy').format(parsedDate);
|
||||
}
|
||||
final parsedDate = DateFormat("dd-MM-yyyy").parse(flightFirstTripDateNotifier.value ?? '');
|
||||
if (parsedDate != null) { _startDateController.text = DateFormat('dd-MM-yyyy').format(parsedDate); }
|
||||
|
||||
final parsedEndDate = DateFormat(
|
||||
"dd-MM-yyyy",
|
||||
).parse(flightLastTripDateNotifier.value ?? '');
|
||||
if (parsedEndDate != null) {
|
||||
_endDateController.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(parsedEndDate);
|
||||
final parsedEndDate = DateFormat("dd-MM-yyyy").parse(flightLastTripDateNotifier.value ?? '');
|
||||
if (parsedEndDate != null) { _endDateController.text = DateFormat('dd-MM-yyyy').format(parsedEndDate); }
|
||||
|
||||
print("parsedDate $parsedDate");
|
||||
print("parsedEndDate $parsedEndDate");
|
||||
|
||||
print("parsedDate");
|
||||
print(parsedDate);
|
||||
print("parsedEndDate");
|
||||
print(parsedEndDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -267,7 +262,8 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
void dispose() {
|
||||
_tripTypeFocusNode.dispose();
|
||||
_tripTypeController.dispose();
|
||||
_startdateController.dispose();
|
||||
_startDateController.dispose();
|
||||
_endDateController.dispose();
|
||||
_insuranceCommentsController.dispose();
|
||||
_nomineeController.dispose();
|
||||
super.dispose();
|
||||
@ -592,7 +588,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
|
||||
setState(() {
|
||||
_selectedCheckOutDate = pickedDate;
|
||||
_startdateController.text = DateFormat(
|
||||
_startDateController.text = DateFormat(
|
||||
'dd-MM-yyyy',
|
||||
).format(pickedDate);
|
||||
});
|
||||
@ -605,7 +601,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
|
||||
// DateTime? checkInDate;
|
||||
// try {
|
||||
// checkInDate = DateTime.parse(_startdateController.text);
|
||||
// checkInDate = DateTime.parse(_startDateController.text);
|
||||
// } catch (e) {
|
||||
// checkInDate = today;
|
||||
// }
|
||||
@ -627,7 +623,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
DateTime? validFromDate;
|
||||
|
||||
try {
|
||||
String fromDateText = _startdateController.text.trim();
|
||||
String fromDateText = _startDateController.text.trim();
|
||||
print("Valid From Text: $fromDateText");
|
||||
if (fromDateText.isNotEmpty) {
|
||||
validFromDate = DateFormat('dd-MM-yyyy').parseStrict(fromDateText);
|
||||
@ -871,7 +867,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldWrapper(
|
||||
isFocused: _dateFocus,
|
||||
isFocused: _startDateFocus,
|
||||
isDesktop: isDesktop,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.11 : null,
|
||||
child: SizedBox(
|
||||
@ -879,7 +875,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
await _selectCheckOutDate(context);
|
||||
if (_startdateController.text.isNotEmpty) {
|
||||
if (_startDateController.text.isNotEmpty) {
|
||||
setState(() {
|
||||
errorMessages.remove(
|
||||
"start_date",
|
||||
@ -889,8 +885,8 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
},
|
||||
child: AbsorbPointer(
|
||||
child: TextField(
|
||||
focusNode: _dateFocusNode,
|
||||
controller: _startdateController,
|
||||
focusNode: _startDateFocusNode,
|
||||
controller: _startDateController,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Select ",
|
||||
@ -929,7 +925,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
CustomTextFieldWrapper(
|
||||
isFocused: _dateFocus,
|
||||
isFocused: _endDateFocus,
|
||||
isDesktop: isDesktop,
|
||||
width: isDesktop ? MediaQuery.of(context).size.width * 0.11 : null,
|
||||
child: SizedBox(
|
||||
@ -939,7 +935,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
await _selectEndCheckOutDate(context);
|
||||
|
||||
if (_endDateController.text.isNotEmpty) {
|
||||
DateTime? startDate = _parseDate(_startdateController.text);
|
||||
DateTime? startDate = _parseDate(_startDateController.text);
|
||||
DateTime? endDate = _parseDate(_endDateController.text);
|
||||
|
||||
if (startDate != null &&
|
||||
@ -958,7 +954,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
},
|
||||
child: AbsorbPointer(
|
||||
child: TextField(
|
||||
focusNode: _dateFocusNode,
|
||||
focusNode: _endDateFocusNode,
|
||||
controller: _endDateController,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
decoration: const InputDecoration(
|
||||
@ -981,9 +977,10 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
if (errorMessages["end_date"] != null) ...[
|
||||
SizedBox(height: 5), // Space before error message
|
||||
Text(
|
||||
// "Required",
|
||||
errorMessages["end_date"]!,
|
||||
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||
style: const TextStyle(color: Colors.red, fontSize: 12),
|
||||
maxLines: 2, // Allow it to wrap onto two lines
|
||||
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@ -334,7 +334,7 @@ class VisaListWidget extends StatelessWidget {
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
" Visa Type",
|
||||
" Country",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 11,
|
||||
),
|
||||
@ -342,7 +342,7 @@ class VisaListWidget extends StatelessWidget {
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
" Country",
|
||||
" Visa Type",
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 11,
|
||||
),
|
||||
@ -372,8 +372,8 @@ class VisaListWidget extends StatelessWidget {
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
getRequestForVisa(
|
||||
item["type_of_visa"]!.toString()),
|
||||
getRequestForCountry(
|
||||
item["country_code"]!.toString()),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
@ -384,8 +384,8 @@ class VisaListWidget extends StatelessWidget {
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
getRequestForCountry(
|
||||
item["country_code"]!.toString()),
|
||||
getRequestForVisa(
|
||||
item["type_of_visa"]!.toString()),
|
||||
style: GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
|
||||
@ -1584,7 +1584,9 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
SizedBox(height: 5), // Space before error message
|
||||
Text(
|
||||
errorMessages["date_of_expiry"]!,
|
||||
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||
style: const TextStyle(color: Colors.red, fontSize: 10),
|
||||
maxLines: 2, // Allow it to wrap onto two lines
|
||||
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows
|
||||
),
|
||||
],
|
||||
],
|
||||
@ -4085,7 +4087,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
// Revalidate expiry
|
||||
if (_selectedCheckOutDate != null &&
|
||||
_selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) {
|
||||
errorMessages["valid_upto"] = "end date cannot be earlier than from date";
|
||||
errorMessages["valid_upto"] = "valid upto cannot be earlier than valid from";
|
||||
} else {
|
||||
errorMessages.remove("valid_upto");
|
||||
}
|
||||
@ -4201,7 +4203,7 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
|
||||
if (_selectedCheckInDate != null &&
|
||||
_selectedCheckOutDate!.isBefore(_selectedCheckInDate!)) {
|
||||
errorMessages["valid_upto"] = "end date cannot be earlier than from date";
|
||||
errorMessages["valid_upto"] = "valid upto cannot be earlier than valid from";
|
||||
} else {
|
||||
errorMessages.remove("valid_upto");
|
||||
}
|
||||
@ -4257,6 +4259,15 @@ class TravellerDetailsState extends State<TravellerDetails> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (errorMessages["valid_upto"] != null) ...[
|
||||
SizedBox(height: 5), // Space before error message
|
||||
Text(
|
||||
errorMessages["valid_upto"]!,
|
||||
style: const TextStyle(color: Colors.red, fontSize: 10),
|
||||
maxLines: 2, // Allow it to wrap onto two lines
|
||||
overflow: TextOverflow.ellipsis, // Add ellipsis if it still overflows
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user