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) {
|
// 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),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -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 {
|
Future<void> _selectEndCheckOutDate(BuildContext context) async {
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
DateTime today = DateTime(now.year, now.month, now.day);
|
DateTime today = DateTime(now.year, now.month, now.day);
|
||||||
|
|
||||||
// DateTime? checkInDate;
|
DateTime? checkInDate;
|
||||||
// try {
|
try {
|
||||||
// checkInDate = DateTime.parse(_startdateController.text);
|
checkInDate = DateTime.parse(_startdateController.text);
|
||||||
// } catch (e) {
|
} catch (e) {
|
||||||
// checkInDate = today;
|
checkInDate = today;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Ensure at least today is used
|
// // Ensure at least today is used
|
||||||
// DateTime firstDate = checkInDate.isAfter(today) ? checkInDate : today;
|
// DateTime firstDate = checkInDate.isAfter(today) ? checkInDate : today;
|
||||||
@ -617,52 +699,20 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
|||||||
// ? _selectedCheckOutDate!
|
// ? _selectedCheckOutDate!
|
||||||
// : firstDate;
|
// : firstDate;
|
||||||
|
|
||||||
// DateTime firstDate = checkInDate;
|
DateTime firstDate = checkInDate;
|
||||||
// DateTime initialDate =
|
DateTime initialDate =
|
||||||
// _selectedCheckOutDate != null &&
|
_selectedCheckOutDate != null &&
|
||||||
// _selectedCheckOutDate!.isAfter(firstDate)
|
_selectedCheckOutDate!.isAfter(firstDate)
|
||||||
// ? _selectedCheckOutDate!
|
? _selectedCheckOutDate!
|
||||||
// : firstDate;
|
: 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(
|
final pickedDate = await showDatePicker(
|
||||||
context: context,
|
context: context,
|
||||||
// initialDate: initialDate,
|
initialDate: initialDate,
|
||||||
// firstDate: initialDate,
|
|
||||||
// firstDate: DateTime(1900),
|
|
||||||
initialDate: firstDate,
|
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
lastDate: DateTime(2100),
|
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(
|
// DateTime? pickedDate = await showDatePicker(
|
||||||
// context: context,
|
// context: context,
|
||||||
// initialDate: _selectedCheckOutDate != null &&
|
// initialDate: _selectedCheckOutDate != null &&
|
||||||
@ -783,7 +833,10 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
|||||||
dropdownDecoratorProps: const DropDownDecoratorProps(
|
dropdownDecoratorProps: const DropDownDecoratorProps(
|
||||||
dropdownSearchDecoration: InputDecoration(
|
dropdownSearchDecoration: InputDecoration(
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 10,),
|
contentPadding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 10,
|
||||||
|
vertical: 10,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
dropdownBuilder: (context, selectedItem) {
|
dropdownBuilder: (context, selectedItem) {
|
||||||
@ -809,14 +862,15 @@ class _InsuranceScreenState extends State<InsuranceScreen> {
|
|||||||
? (Map<String, dynamic>? newValue) {
|
? (Map<String, dynamic>? newValue) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedInsuranceType = newValue?['dropdown_key'];
|
selectedInsuranceType = newValue?['dropdown_key'];
|
||||||
print("selected Insurance Type: ${selectedInsuranceType}");
|
print(
|
||||||
|
"selected Insurance Type: ${selectedInsuranceType}",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@ -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