validations

This commit is contained in:
venbaittech 2025-06-10 19:22:47 +05:30
parent 26ece5fb8a
commit 0537c45545
2 changed files with 39 additions and 4 deletions

View File

@ -623,8 +623,33 @@ class FlightScreenState extends State<FlightScreen> {
errorMessages["time_$i"] = "Required";
}
}
//selectedFrom For every trips should n't same
Set<String?> seenFrom = {};
Set<String?> seenTo = {};
// Step 2: Sequential Date Comparison
for (int i = 1; i <= rowCount; i++) {
final fromValue = selectedFrom[i];
final toValue = selectedTo[i];
if (fromValue != null) {
if (seenFrom.contains(fromValue)) {
errorMessages["from_place_$i"] = "Duplicate Departure ";
print("Error: from_place_$i duplicates a previous departure");
} else {
seenFrom.add(fromValue);
}
}
if (toValue != null) {
if (seenTo.contains(toValue)) {
errorMessages["to_place_$i"] = "Duplicate Destination ";
print("Error: to_place_$i duplicates a previous departure");
} else {
seenTo.add(toValue);
}
}
}
// Step 3: Sequential Date Comparison
DateFormat format = DateFormat("dd-MM-yyyy"); // Assumes "12 Jun" format
DateTime now = DateTime.now();
List<DateTime> parsedDates = [];
@ -1561,7 +1586,10 @@ class FlightScreenState extends State<FlightScreen> {
),
if (errorMessages["from_place_$index"] != null) ...[
SizedBox(height: 5), // Space before error message
Text("Required", style: TextStyle(color: Colors.red, fontSize: 12)),
Text(
errorMessages["from_place_$index"]!,
style: TextStyle(color: Colors.red, fontSize: 12),
),
],
],
),

View File

@ -265,7 +265,8 @@ class _ForexScreenState extends State<ForexScreen> {
if (checkEndDate.isBefore(checkStartDate)) {
errorMessages["end_date"] =
"End date cannot be earlier than start date";;
"End date cannot be earlier than start date";
;
}
} catch (e) {
errorMessages["end_date"] = "Invalid date format";
@ -315,7 +316,13 @@ class _ForexScreenState extends State<ForexScreen> {
Map<String, dynamic> data = forexData;
if (!isValidForexData(data)) { // && errorMessages.isNotEmpty) {
final card = data["deposit_on_card"];
final cash = data["deposit_on_cash"];
print("card - $card");
print("cash - $cash");
if (!isValidForexData(data)) {
// && errorMessages.isNotEmpty) {
print("Validation Failed: Required fields are missing.");
setState(() {});
return; // Stop execution if validation fails