validations
This commit is contained in:
parent
2e85273b06
commit
2a77ebc7d1
@ -636,6 +636,8 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
print("Error: from_place_$i duplicates a previous departure");
|
||||
} else {
|
||||
seenFrom.add(fromValue);
|
||||
|
||||
errorMessages.remove("from_place_$i");
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,6 +646,7 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
errorMessages["to_place_$i"] = "Duplicate Destination ";
|
||||
print("Error: to_place_$i duplicates a previous departure");
|
||||
} else {
|
||||
errorMessages.remove("to_place_$i");
|
||||
seenTo.add(toValue);
|
||||
}
|
||||
}
|
||||
@ -663,7 +666,7 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
try {
|
||||
DateTime date = format.parseStrict(dateStr);
|
||||
date = DateTime(
|
||||
now.year,
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
); // Assume current year
|
||||
@ -709,6 +712,8 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
} else if (!parsedDates[i].isAfter(parsedDates[i - 1])) {
|
||||
errorMessages["date_${i + 1}"] = "Must be after date_${i}";
|
||||
print("Error: date_${i + 1} is not after date_${i}");
|
||||
} else {
|
||||
errorMessages.remove("date_${i + 1}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -267,6 +267,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
errorMessages["end_date"] =
|
||||
"End date cannot be earlier than start date";
|
||||
;
|
||||
} else if (checkEndDate.isAtSameMomentAs(checkStartDate)) {
|
||||
setState(() {
|
||||
errorMessages["end_date"] =
|
||||
"Start and end dates cannot be the same";
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
errorMessages["end_date"] = "Invalid date format";
|
||||
@ -320,6 +325,16 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
final cash = data["deposit_on_cash"];
|
||||
print("card - $card");
|
||||
print("cash - $cash");
|
||||
// Call validations first (they populate errorMessages)
|
||||
_validateCardAmount(card);
|
||||
_validateCashAmount(cash);
|
||||
|
||||
// Now check if any errors exist
|
||||
if (errorMessages.isNotEmpty) {
|
||||
print("Validation Failed: ${errorMessages}");
|
||||
setState(() {}); // Refresh UI with error messages
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidForexData(data)) {
|
||||
// && errorMessages.isNotEmpty) {
|
||||
@ -495,6 +510,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
// Check if all required fields have data
|
||||
bool _isForexDataDurationComplete() {
|
||||
print("Calculate 13ww Duration");
|
||||
final data = getForexData;
|
||||
return (data["start_date"]?.isNotEmpty ?? false) &&
|
||||
(data["end_date"]?.isNotEmpty ?? false);
|
||||
@ -503,7 +519,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
// Handle field changes
|
||||
void _onFieldChanged() {
|
||||
if (_isForexDataDurationComplete()) {
|
||||
print("Calculate 1");
|
||||
print("Calculate 1 Duration");
|
||||
CalculateDuration();
|
||||
}
|
||||
|
||||
@ -517,7 +533,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
}
|
||||
|
||||
void CalculateDuration() {
|
||||
print("Calculate 2");
|
||||
print("Calculate 2 Duration");
|
||||
final data = getForexData;
|
||||
final startDateString = data["start_date"];
|
||||
final endDateString = data["end_date"];
|
||||
@ -539,7 +555,7 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
|
||||
// Calculate difference
|
||||
final durationInDays =
|
||||
endDate.difference(startDate).inDays + 1; // +1 to include both days
|
||||
endDate.difference(startDate).inDays; // +1 to include both days
|
||||
|
||||
// You can now use durationInDays however you want:
|
||||
print("Duration: $durationInDays days");
|
||||
@ -976,19 +992,37 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
textControllers["_forexEndDate"]!.text,
|
||||
);
|
||||
|
||||
if (startDate != null &&
|
||||
endDate != null &&
|
||||
endDate.isBefore(startDate)) {
|
||||
if (startDate != null && endDate != null) {
|
||||
if (endDate.isBefore(startDate)) {
|
||||
setState(() {
|
||||
errorMessages["end_date"] =
|
||||
"End date cannot be earlier than start date";
|
||||
});
|
||||
} else if (endDate.isAtSameMomentAs(startDate)) {
|
||||
setState(() {
|
||||
errorMessages["end_date"] =
|
||||
"Start and end dates cannot be the same";
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
errorMessages.remove("end_date");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// if (startDate != null &&
|
||||
// endDate != null &&
|
||||
// endDate.isBefore(startDate)) {
|
||||
// setState(() {
|
||||
// errorMessages["end_date"] =
|
||||
// "End date cannot be earlier than start date";
|
||||
// });
|
||||
// } else {
|
||||
// setState(() {
|
||||
// errorMessages.remove("end_date");
|
||||
// });
|
||||
// }
|
||||
}
|
||||
},
|
||||
child: AbsorbPointer(
|
||||
child: TextField(
|
||||
@ -1062,6 +1096,11 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
errorMessages["end_date"] =
|
||||
"End date cannot be earlier than start date";
|
||||
});
|
||||
} else if (endDate!.isAtSameMomentAs(startDate!)) {
|
||||
setState(() {
|
||||
errorMessages["end_date"] =
|
||||
"Start and end dates cannot be the same";
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
errorMessages.remove("end_date");
|
||||
@ -1098,7 +1137,8 @@ class _ForexScreenState extends State<ForexScreen> {
|
||||
errorMessages["end_date"]!,
|
||||
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
|
||||
overflow:
|
||||
TextOverflow.ellipsis, // Add ellipsis if it still overflows
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@ -64,6 +64,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
final Map<String, TextEditingController> controllers = {};
|
||||
bool isViewMode = false;
|
||||
bool isEditProfile = false;
|
||||
|
||||
// late final List<dynamic>? apiCountryData ;
|
||||
|
||||
late List<dynamic>? apiCountryData;
|
||||
@ -86,6 +87,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
|
||||
String? selectedCountry;
|
||||
String? selectedGender;
|
||||
|
||||
// String? selectedGender = personalDetailsKey.currentState?.selectedGender;
|
||||
|
||||
String? selectedUserType;
|
||||
@ -656,9 +658,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
// printFormData();
|
||||
|
||||
bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false;
|
||||
if (selectedTab == "travel" ||
|
||||
selectedRole == "5" ||
|
||||
setSelectesUserType == true) {
|
||||
if (selectedRole == "5" || setSelectesUserType == true) {
|
||||
print("NO validation");
|
||||
|
||||
Map<String, dynamic> data = userDetials;
|
||||
@ -702,30 +702,64 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
|
||||
// block-submit-here
|
||||
|
||||
// Additional validation starts - travelDetailsData passport
|
||||
DateTime? start_Date = travelDetailsData?['date_of_issue'];
|
||||
DateTime? end_Date = travelDetailsData?['date_of_expiry'];
|
||||
|
||||
if (start_Date != null && end_Date != null && start_Date.toString().isNotEmpty && end_Date.toString().isNotEmpty) {
|
||||
try {
|
||||
final format = DateFormat("dd-MM-yyyy");
|
||||
final checkStartDate = format.parse("$start_Date");
|
||||
final checkEndDate = format.parse("$end_Date");
|
||||
|
||||
if (checkEndDate.isBefore(checkStartDate)) {
|
||||
// return "End date cannot be earlier than start date";;
|
||||
return ;
|
||||
DateTime? start_Date;
|
||||
DateTime? end_Date;
|
||||
|
||||
try {
|
||||
if (travelDetailsData?['date_of_issue'] != null &&
|
||||
travelDetailsData!['date_of_issue'].toString().isNotEmpty) {
|
||||
start_Date = format.parse(travelDetailsData!['date_of_issue']);
|
||||
}
|
||||
} catch (e) { // return "End date cannot be earlier than start date";
|
||||
return ;
|
||||
// errorMessages["end_date"] = "Invalid date format";
|
||||
if (travelDetailsData?['date_of_expiry'] != null &&
|
||||
travelDetailsData!['date_of_expiry'].toString().isNotEmpty) {
|
||||
end_Date = format.parse(travelDetailsData!['date_of_expiry']);
|
||||
}
|
||||
|
||||
if (start_Date != null &&
|
||||
end_Date != null &&
|
||||
end_Date.isBefore(start_Date)) {
|
||||
print("End date cannot be earlier than start date");
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
print("Invalid passport date format");
|
||||
return;
|
||||
}
|
||||
|
||||
// Additional validation starts - travelDetailsData passport
|
||||
// DateTime? start_Date = travelDetailsData?['date_of_issue'];
|
||||
// DateTime? end_Date = travelDetailsData?['date_of_expiry'];
|
||||
//
|
||||
// if (start_Date != null &&
|
||||
// end_Date != null &&
|
||||
// start_Date.toString().isNotEmpty &&
|
||||
// end_Date.toString().isNotEmpty) {
|
||||
// try {
|
||||
// final format = DateFormat("dd-MM-yyyy");
|
||||
// final checkStartDate = format.parse("$start_Date");
|
||||
// final checkEndDate = format.parse("$end_Date");
|
||||
//
|
||||
// if (checkEndDate.isBefore(checkStartDate)) {
|
||||
// // return "End date cannot be earlier than start date";;
|
||||
// return;
|
||||
// }
|
||||
// } catch (e) {
|
||||
// // return "End date cannot be earlier than start date";
|
||||
// return;
|
||||
// // errorMessages["end_date"] = "Invalid date format";
|
||||
// }
|
||||
// }
|
||||
|
||||
// valid_from: 20-06-2025, valid_upto: 19-06-2025
|
||||
DateTime? valid_from = data?['valid_from'];
|
||||
DateTime? valid_upto = data?['valid_upto'];
|
||||
|
||||
if (valid_from != null && valid_upto != null && valid_from.toString().isNotEmpty && valid_upto.toString().isNotEmpty) {
|
||||
if (valid_from != null &&
|
||||
valid_upto != null &&
|
||||
valid_from.toString().isNotEmpty &&
|
||||
valid_upto.toString().isNotEmpty) {
|
||||
try {
|
||||
final format = DateFormat("dd-MM-yyyy");
|
||||
final checkValidFrom = format.parse("$valid_from");
|
||||
@ -733,10 +767,11 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
|
||||
if (checkValidUpto.isBefore(checkValidFrom)) {
|
||||
// return "valid upto cannot be earlier than valid from";
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
} catch (e) { // return "valid upto cannot be earlier than valid from";
|
||||
return ;
|
||||
} catch (e) {
|
||||
// return "valid upto cannot be earlier than valid from";
|
||||
return;
|
||||
// errorMessages["end_date"] = "Invalid date format";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
<base href="/tstat/">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user