date validation merge
This commit is contained in:
parent
f1c153162b
commit
26ece5fb8a
@ -612,14 +612,81 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
// if (textControllers["_to${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||
// 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) {
|
||||
errorMessages["date_$i"] = "Required";
|
||||
}
|
||||
|
||||
if (textControllers["_time${i}Controller"]?.text.trim().isEmpty ?? true) {
|
||||
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
|
||||
|
||||
return errorMessages
|
||||
@ -1872,7 +1939,10 @@ class FlightScreenState extends State<FlightScreen> {
|
||||
),
|
||||
if (errorMessages["date_$index"] != null) ...[
|
||||
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),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@ -599,16 +599,98 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// Future<void> _selectEndCheckOutDate(BuildContext context) async {
|
||||
// DateTime now = DateTime.now();
|
||||
// DateTime today = DateTime(now.year, now.month, now.day);
|
||||
//
|
||||
// // DateTime? checkInDate;
|
||||
// // try {
|
||||
// // checkInDate = DateTime.parse(_startdateController.text);
|
||||
// // } catch (e) {
|
||||
// // checkInDate = today;
|
||||
// // }
|
||||
//
|
||||
// // // Ensure at least today is used
|
||||
// // DateTime firstDate = checkInDate.isAfter(today) ? checkInDate : today;
|
||||
// // DateTime initialDate = _selectedCheckOutDate != null &&
|
||||
// // _selectedCheckOutDate!.isAfter(firstDate)
|
||||
// // ? _selectedCheckOutDate!
|
||||
// // : firstDate;
|
||||
//
|
||||
// // DateTime firstDate = checkInDate;
|
||||
// // DateTime initialDate =
|
||||
// // _selectedCheckOutDate != null &&
|
||||
// // _selectedCheckOutDate!.isAfter(firstDate)
|
||||
// // ? _selectedCheckOutDate!
|
||||
// // : firstDate;
|
||||
//
|
||||
// DateTime? validFromDate;
|
||||
//
|
||||
// try {
|
||||
// String fromDateText = _startdateController.text.trim();
|
||||
// print("Valid From Text: $fromDateText");
|
||||
// if (fromDateText.isNotEmpty) {
|
||||
// validFromDate = DateFormat('dd-MM-yyyy').parseStrict(fromDateText);
|
||||
// print("Parsed Valid From: $validFromDate");
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("Error parsing valid from date: $e");
|
||||
// }
|
||||
//
|
||||
// // Use max(today, validFromDate) as firstDate
|
||||
// // DateTime firstDate = today;
|
||||
// DateTime firstDate = validFromDate ?? today;
|
||||
// if (validFromDate != null && validFromDate.isAfter(today)) {
|
||||
// firstDate = validFromDate;
|
||||
// }
|
||||
// final pickedDate = await showDatePicker(
|
||||
// context: context,
|
||||
// // initialDate: initialDate,
|
||||
// // firstDate: initialDate,
|
||||
// // firstDate: DateTime(1900),
|
||||
// initialDate: firstDate,
|
||||
// firstDate: firstDate,
|
||||
// lastDate: DateTime(2100),
|
||||
// initialEntryMode: DatePickerEntryMode.calendarOnly,
|
||||
// );
|
||||
//
|
||||
// // final pickedDate = await showDatePicker(
|
||||
// // context: context,
|
||||
// // // initialDate: initialDate,
|
||||
// // initialDate: initialDate,
|
||||
// // firstDate: initialDate,
|
||||
// // lastDate: DateTime(2100),
|
||||
// // initialEntryMode: DatePickerEntryMode.calendarOnly,
|
||||
// // );
|
||||
//
|
||||
// // DateTime? pickedDate = await showDatePicker(
|
||||
// // context: context,
|
||||
// // initialDate: _selectedCheckOutDate != null &&
|
||||
// // _selectedCheckOutDate!.isAfter(today)
|
||||
// // ? _selectedCheckOutDate!
|
||||
// // : today,
|
||||
// // firstDate: today,
|
||||
// // lastDate: DateTime(2100),
|
||||
// // );
|
||||
//
|
||||
// if (pickedDate != null && pickedDate != _selectedCheckOutDate) {
|
||||
// setState(() {
|
||||
// _selectedCheckOutDate = pickedDate;
|
||||
// _endDateController.text = DateFormat('dd-MM-yyyy').format(pickedDate);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> _selectEndCheckOutDate(BuildContext context) async {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
// DateTime? checkInDate;
|
||||
// try {
|
||||
// checkInDate = DateTime.parse(_startdateController.text);
|
||||
// } catch (e) {
|
||||
// checkInDate = today;
|
||||
// }
|
||||
DateTime? checkInDate;
|
||||
try {
|
||||
checkInDate = DateTime.parse(_startdateController.text);
|
||||
} catch (e) {
|
||||
checkInDate = today;
|
||||
}
|
||||
|
||||
// // Ensure at least today is used
|
||||
// DateTime firstDate = checkInDate.isAfter(today) ? checkInDate : today;
|
||||
@ -617,52 +699,20 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
// ? _selectedCheckOutDate!
|
||||
// : firstDate;
|
||||
|
||||
// DateTime firstDate = checkInDate;
|
||||
// DateTime initialDate =
|
||||
// _selectedCheckOutDate != null &&
|
||||
// _selectedCheckOutDate!.isAfter(firstDate)
|
||||
// ? _selectedCheckOutDate!
|
||||
// : firstDate;
|
||||
DateTime firstDate = checkInDate;
|
||||
DateTime initialDate =
|
||||
_selectedCheckOutDate != null &&
|
||||
_selectedCheckOutDate!.isAfter(firstDate)
|
||||
? _selectedCheckOutDate!
|
||||
: firstDate;
|
||||
|
||||
DateTime? validFromDate;
|
||||
|
||||
try {
|
||||
String fromDateText = _startdateController.text.trim();
|
||||
print("Valid From Text: $fromDateText");
|
||||
if (fromDateText.isNotEmpty) {
|
||||
validFromDate = DateFormat('dd-MM-yyyy').parseStrict(fromDateText);
|
||||
print("Parsed Valid From: $validFromDate");
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error parsing valid from date: $e");
|
||||
}
|
||||
|
||||
// Use max(today, validFromDate) as firstDate
|
||||
// DateTime firstDate = today;
|
||||
DateTime firstDate = validFromDate ?? today;
|
||||
if (validFromDate != null && validFromDate.isAfter(today)) {
|
||||
firstDate = validFromDate;
|
||||
}
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
// initialDate: initialDate,
|
||||
// firstDate: initialDate,
|
||||
// firstDate: DateTime(1900),
|
||||
initialDate: firstDate,
|
||||
initialDate: initialDate,
|
||||
firstDate: firstDate,
|
||||
lastDate: DateTime(2100),
|
||||
initialEntryMode: DatePickerEntryMode.calendarOnly,
|
||||
);
|
||||
|
||||
// final pickedDate = await showDatePicker(
|
||||
// context: context,
|
||||
// // initialDate: initialDate,
|
||||
// initialDate: initialDate,
|
||||
// firstDate: initialDate,
|
||||
// lastDate: DateTime(2100),
|
||||
// initialEntryMode: DatePickerEntryMode.calendarOnly,
|
||||
// );
|
||||
|
||||
// DateTime? pickedDate = await showDatePicker(
|
||||
// context: context,
|
||||
// initialDate: _selectedCheckOutDate != null &&
|
||||
@ -756,7 +806,7 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
child: DropdownSearch<Map<String, dynamic>>(
|
||||
items: purposeList.cast<Map<String, dynamic>>(),
|
||||
selectedItem: purposeList.firstWhere(
|
||||
(item) => item['dropdown_key'] == selectedInsuranceType,
|
||||
(item) => item['dropdown_key'] == selectedInsuranceType,
|
||||
orElse: () => {},
|
||||
),
|
||||
itemAsString: (item) => item['dropdown_value'] ?? '',
|
||||
@ -783,7 +833,10 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
dropdownDecoratorProps: const DropDownDecoratorProps(
|
||||
dropdownSearchDecoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 10,),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
dropdownBuilder: (context, selectedItem) {
|
||||
@ -805,18 +858,19 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
||||
);
|
||||
},
|
||||
onChanged:
|
||||
purposeList.isNotEmpty
|
||||
? (Map<String, dynamic>? newValue) {
|
||||
setState(() {
|
||||
selectedInsuranceType= newValue?['dropdown_key'];
|
||||
print("selected Insurance Type: ${selectedInsuranceType}");
|
||||
});
|
||||
}
|
||||
: null,
|
||||
purposeList.isNotEmpty
|
||||
? (Map<String, dynamic>? newValue) {
|
||||
setState(() {
|
||||
selectedInsuranceType = newValue?['dropdown_key'];
|
||||
print(
|
||||
"selected Insurance Type: ${selectedInsuranceType}",
|
||||
);
|
||||
});
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
@ -582,7 +582,6 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
||||
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
||||
|
||||
|
||||
print("TRAVEL DETAILS FROM CHILD: $travelDetailsData");
|
||||
|
||||
Map<String, dynamic> data = userDetials;
|
||||
@ -657,56 +656,38 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
// printFormData();
|
||||
|
||||
bool isValid = travellerDetailsKey.currentState?.boolValidation() ?? false;
|
||||
if (selectedTab == "travel" ||
|
||||
selectedRole == "5" ||
|
||||
setSelectesUserType == true) {
|
||||
print("NO validation");
|
||||
|
||||
print("isValid- $isValid");
|
||||
if (!isValid) {
|
||||
print("Validation failed. Please check the inputs.");
|
||||
setState(() {});
|
||||
return; // ❌ STOP execution here if not valid
|
||||
}
|
||||
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");
|
||||
if (!isValid) {
|
||||
print("Validation failed. Please check the inputs.");
|
||||
setState(() {});
|
||||
return; // ❌ STOP execution here if not valid
|
||||
}
|
||||
|
||||
travelDetailsData = travellerDetailsKey.currentState?.travel_Detials;
|
||||
|
||||
print("travelDetailsData - $travelDetailsData");
|
||||
|
||||
// Additional validation starts - travelDetailsData passport
|
||||
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;
|
||||
print("travelDetailsData - $travelDetailsData");
|
||||
// errorMessagesTravel = travellerDetailsKey.currentState!.errorMessages;
|
||||
|
||||
print("TRAVEL DETAILS FROM CHILD");
|
||||
// print("TRAVEL DETAILS FROM CHILD: $travelDetailsData");
|
||||
@ -731,6 +712,7 @@ class _CreateUserFormDetialsState extends State<CreateUserFormDetials> {
|
||||
orgId = await getOrgId();
|
||||
|
||||
createUserData(userDetials);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
// import 'package:flutter/rendering.dart';
|
||||
import 'dart:html' as html;
|
||||
import 'package:frontend/config/apiUrl.dart'; // 1 newly added
|
||||
import 'package:frontend/services/apiService.dart';
|
||||
@ -31,7 +31,7 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
||||
// SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here
|
||||
if (kIsWeb) {
|
||||
final uri = Uri.parse(html.window.location.href);
|
||||
if (uri.path == '/authredirection' &&
|
||||
|
||||
Loading…
Reference in New Issue
Block a user