merge with old
This commit is contained in:
commit
5a3c2a7fb9
@ -612,14 +612,81 @@ class FlightScreenState extends State<FlightScreen> {
|
|||||||
// if (textControllers["_to${i}Controller"]?.text.trim().isEmpty ?? true) {
|
// if (textControllers["_to${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||||
// errorMessages["to_place_$i"] = "Required";
|
// errorMessages["to_place_$i"] = "Required";
|
||||||
// }
|
// }
|
||||||
|
// if (textControllers["_date${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||||
|
// errorMessages["date_$i"] = "Required";
|
||||||
|
// }
|
||||||
if (textControllers["_date${i}Controller"]?.text.trim().isEmpty ?? true) {
|
if (textControllers["_date${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||||
errorMessages["date_$i"] = "Required";
|
errorMessages["date_$i"] = "Required";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textControllers["_time${i}Controller"]?.text.trim().isEmpty ?? true) {
|
if (textControllers["_time${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||||
errorMessages["time_$i"] = "Required";
|
errorMessages["time_$i"] = "Required";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 2: Sequential Date Comparison
|
||||||
|
DateFormat format = DateFormat("dd-MM-yyyy"); // Assumes "12 Jun" format
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
List<DateTime> parsedDates = [];
|
||||||
|
|
||||||
|
for (int i = 1; i <= rowCount; i++) {
|
||||||
|
String? dateStr = textControllers["_date${i}Controller"]?.text.trim();
|
||||||
|
String? timeStr = textControllers["_time${i}Controller"]?.text.trim();
|
||||||
|
|
||||||
|
print("VAlidationDATE - $dateStr ");
|
||||||
|
if (dateStr != null && dateStr.isNotEmpty) {
|
||||||
|
try {
|
||||||
|
DateTime date = format.parseStrict(dateStr);
|
||||||
|
date = DateTime(
|
||||||
|
now.year,
|
||||||
|
date.month,
|
||||||
|
date.day,
|
||||||
|
); // Assume current year
|
||||||
|
parsedDates.add(date);
|
||||||
|
} catch (e) {
|
||||||
|
errorMessages["date_$i"] = "Invalid format";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < parsedDates.length; i++) {
|
||||||
|
if (parsedDates[i].isAtSameMomentAs(parsedDates[i - 1])) {
|
||||||
|
//Here check time[i] and time[i-1] if same error 30 mins gap reeuired
|
||||||
|
print("Ckecking Same DAte");
|
||||||
|
// Same date - check time gap
|
||||||
|
// Combine parsedDates and times into DateTime objects
|
||||||
|
String prevDateStr =
|
||||||
|
textControllers["_date${i}Controller"]!.text.trim();
|
||||||
|
String prevTimeStr =
|
||||||
|
textControllers["_time${i}Controller"]!.text.trim();
|
||||||
|
String currDateStr =
|
||||||
|
textControllers["_date${i + 1}Controller"]!.text.trim();
|
||||||
|
String currTimeStr =
|
||||||
|
textControllers["_time${i + 1}Controller"]!.text.trim();
|
||||||
|
|
||||||
|
final dtFormat = DateFormat("dd-MM-yyyy HH:mm");
|
||||||
|
final prevDT = dtFormat.parse("$prevDateStr $prevTimeStr");
|
||||||
|
final currDT = dtFormat.parse("$currDateStr $currTimeStr");
|
||||||
|
|
||||||
|
int diffMins = currDT.difference(prevDT).inMinutes;
|
||||||
|
print("Time difference between row ${i} and ${i + 1}: $diffMins mins");
|
||||||
|
|
||||||
|
// If same day (diff >= 0 & < 1440 minutes), enforce 30‑min minimum gap
|
||||||
|
if (diffMins < 0) {
|
||||||
|
errorMessages["time_${i + 1}"] = "Must be after previous";
|
||||||
|
} else if (diffMins < 30) {
|
||||||
|
errorMessages["time_${i + 1}"] = "30 mins gap required";
|
||||||
|
} else {
|
||||||
|
errorMessages.remove("time_${i + 1}");
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Ckecking Same DAte...1");
|
||||||
|
} 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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {}); // Update UI to show error messages
|
setState(() {}); // Update UI to show error messages
|
||||||
|
|
||||||
return errorMessages
|
return errorMessages
|
||||||
@ -1872,7 +1939,10 @@ class FlightScreenState extends State<FlightScreen> {
|
|||||||
),
|
),
|
||||||
if (errorMessages["date_$index"] != null) ...[
|
if (errorMessages["date_$index"] != 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(
|
||||||
|
errorMessages["date_$index"]!,
|
||||||
|
style: TextStyle(color: Colors.red, fontSize: 12),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -582,7 +582,6 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
|||||||
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
||||||
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
||||||
|
|
||||||
|
|
||||||
print("TRAVEL DETAILS FROM CHILD: $travelDetailsData");
|
print("TRAVEL DETAILS FROM CHILD: $travelDetailsData");
|
||||||
|
|
||||||
Map<String, dynamic> data = userDetials;
|
Map<String, dynamic> data = userDetials;
|
||||||
@ -657,7 +656,25 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
|||||||
// printFormData();
|
// printFormData();
|
||||||
|
|
||||||
bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false;
|
bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false;
|
||||||
|
if (selectedTab == "travel" ||
|
||||||
|
selectedRole == "5" ||
|
||||||
|
setSelectesUserType == true) {
|
||||||
|
print("NO validation");
|
||||||
|
|
||||||
|
Map<String, dynamic> data = userDetials;
|
||||||
|
|
||||||
|
if (!isValidData(data)) {
|
||||||
|
print("USERDETAILS : $userDetials");
|
||||||
|
print("Validation Failed: Required fields are missing.");
|
||||||
|
setState(() {});
|
||||||
|
return; // Stop execution if validation fails
|
||||||
|
} else {
|
||||||
|
print("USERDETAILS : $userDetials");
|
||||||
|
orgId = await getOrgId();
|
||||||
|
|
||||||
|
createUserData(userDetials);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
print("isValid- $isValid");
|
print("isValid- $isValid");
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
print("Validation failed. Please check the inputs.");
|
print("Validation failed. Please check the inputs.");
|
||||||
@ -667,45 +684,9 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
|||||||
|
|
||||||
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
||||||
|
|
||||||
|
print("travelDetailsData - $travelDetailsData");
|
||||||
|
|
||||||
// Additional validation starts - travelDetailsData passport
|
print("travelDetailsData - $travelDetailsData");
|
||||||
String start_Date = travelDetailsData?['date_of_issue'];
|
|
||||||
String 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// String valid_from = travelDetailsData?['valid_from'];
|
|
||||||
// String valid_upto = travelDetailsData?['valid_upto'];
|
|
||||||
//
|
|
||||||
// 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");
|
|
||||||
// final checkValidUpto = format.parse("$valid_upto");
|
|
||||||
//
|
|
||||||
// if (checkValidUpto.isBefore(checkValidFrom)) {
|
|
||||||
// // 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";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
||||||
|
|
||||||
print("TRAVEL DETAILS FROM CHILD");
|
print("TRAVEL DETAILS FROM CHILD");
|
||||||
@ -733,6 +714,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
|||||||
createUserData(userDetials);
|
createUserData(userDetials);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool isValidData(Map<String, dynamic> data) {
|
bool isValidData(Map<String, dynamic> data) {
|
||||||
errorMessages.clear(); // Reset errors
|
errorMessages.clear(); // Reset errors
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
// import 'package:flutter/rendering.dart';
|
||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
import 'package:frontend/config/apiUrl.dart'; // 1 newly added
|
import 'package:frontend/config/apiUrl.dart'; // 1 newly added
|
||||||
import 'package:frontend/services/apiService.dart';
|
import 'package:frontend/services/apiService.dart';
|
||||||
@ -31,7 +31,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
// SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
final uri = Uri.parse(html.window.location.href);
|
final uri = Uri.parse(html.window.location.href);
|
||||||
if (uri.path == '/authredirection' &&
|
if (uri.path == '/authredirection' &&
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user