minor issues fixes 6

This commit is contained in:
venba-Inspriron-3558 2025-06-25 18:28:58 +05:30
parent c0ecff7697
commit 179e1db5d7
3 changed files with 92 additions and 47 deletions

View File

@ -94,8 +94,10 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
setState(() {
_users = userList.map((user) => SearchUser.fromJson(user)).toList();
_filteredUsers = List.from(_users);
});
_filterUsers("");
});
print("filtered user === ${_filteredUsers.length}");
print("Users fetched: ${_users.length}");
for (var user in _users) {
print("${user.firstName} ${user.lastName} ${user.empCode}");
@ -136,7 +138,7 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
if (response.statusCode == 200) {
final Map<String, dynamic> responseBody = json.decode(response.body);
print("API Response: $responseBody"); // Debugging
print("API Traveller Response: $responseBody"); // Debugging
if (responseBody.containsKey('data') && responseBody['data'] is List) {
List<dynamic> travellerList = responseBody['data'];
@ -147,6 +149,7 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
.map((user) => SearchTraveler.fromJson(user))
.toList();
_filteredTraveller = List.from(_traveller);
_filterTravellers("");
});
print("Users fetched: ${_users.length}");
@ -201,21 +204,28 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
// }
void _filterUsers(String query) {
print("Filtering _filterUsersTravellers...");
print("Filtering _filterUsers... ${_filteredUsers.length}");
setState(() {
_filteredList.clear(); // Reset the list before filtering
final excludedUserId = widget.currentUser.toString();
if (query.isEmpty) {
_filteredList = [
// ..._users.map((user) => {"type": "user", "data": user}),
..._users
.where(
(user) =>
(user.userId.toString() == excludedUserId &&
user.roleId.toString() == "5"),
) // Exclude user ID 4
.map((user) => {"type": "user", "data": user}),
];
// Return all users excluding self and roleId == 5
_filteredList = _users.where((user) =>
user.userId.toString() != excludedUserId && user.roleId.toString() != "5")
.map((user) => {"type": "user", "data": user})
.toList();
// _filteredList = [
// // ..._users.map((user) => {"type": "user", "data": user}),
// ..._users
// .where(
// (user) =>
// (user.userId.toString() == excludedUserId &&
// user.roleId.toString() == "5"),
// ) // Exclude user ID 4
// .map((user) => {"type": "user", "data": user}),
// ];
} else {
_filteredList = [
..._users
@ -243,7 +253,17 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
}
});
print("Filtered List:");
// setState(() {
// print("Called 2.1");
// print("h1 - ${_filteredUsers}");
// if (query.isEmpty) {
// _filteredList = _filteredUsers
// .map((user) => {"type": "user", "data": user})
// .toList();
// }
//
// });
for (var item in _filteredList) {
var user = item["data"];
print(
@ -253,14 +273,16 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
}
void _filterTravellers(String query) {
print("Filtering _filterUsersTravellers...");
print("Filtering _filterTravellers...");
setState(() {
_filteredList.clear(); // Reset the list before filtering
if (query.isEmpty) {
_filteredList = [
..._users.map((user) => {"type": "user", "data": user}),
];
_filteredList = _traveller
.map((traveller) => {"type": "traveller", "data": traveller})
.toList();
// _filteredList = [
// ..._users.map((user) => {"type": "user", "data": user}),
// ];
} else {
_filteredList = [
..._traveller
@ -289,6 +311,15 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
}
}
void _filterByTitle(String query) {
print("filtered by title");
if (widget.title == "Others (Non Employee)") {
_filterTravellers(query);
} else {
_filterUsers(query);
}
}
void _filterUsersTravellers(String query) {
print("Filtering _filterUsersTravellers...");
setState(() {
@ -346,13 +377,19 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
@override
void initState() {
super.initState();
fetchUsers();
fetchTraveller();
if (widget.title == "Others (Non Employee)"){ fetchTraveller(); }
else{ fetchUsers(); }
print("SelffsdfcurrentUser - ${widget.currentUser}");
_filterByTitle("");
}
@override
Widget build(BuildContext context) {
final isValid = _searchController.text.trim().isNotEmpty &&
userIdSelected.trim().isNotEmpty;
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Container(
@ -442,8 +479,10 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
SizedBox(height: 5),
// User List or Message
_searchController.text.isNotEmpty
? SizedBox(
// _searchController.text.isNotEmpty
// ?
if (!_showTravellerForm)
SizedBox(
height: 300, // Limit height to avoid overflow
// child: _filteredUsers.isEmpty
child:
@ -468,31 +507,33 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
final userType =
item["type"]; // "user" or "traveller"
if (user is Map<String, dynamic>) {
print(
"userLsirer - ${jsonEncode(user)}",
); // pretty JSON-like string
print("userLsirer - ${jsonEncode(user)}"); // pretty JSON-like string
} else {
print("userLsirer - $user"); // fallback
}
final isSelected = userIdSelected == (userType == "user" ? user.userId : user.travellerId);
return ListTile(
// hoverColor: ,
title: Text(
"${user.firstName ?? "Unknown"} ${user.lastName ?? ""}",
style: GoogleFonts.poppins(fontSize: 11),
"${user.firstName ?? "Unknown"}" "${(user.lastName?.isNotEmpty ?? false) ? " ${user.lastName}" : ""}",
style: GoogleFonts.poppins(fontSize: 11 , color: isSelected ? widget.layoutColorForUser : Colors.black),
),
subtitle:
userType == "user"
? Text(
"Employee ID: ${user.empCode ?? ""} ",
"Employee ID: ${user.empCode ?? "-"} ",
// "Employee ID: ${userType == "user" ? user.userId : user.travellerId}",
style: GoogleFonts.poppins(
fontSize: 10,
color: isSelected ? widget.layoutColorForUser : Colors.black,
),
)
: Text(
"Mobile : ${user.mobileNo ?? ""} ",
"Mobile : ${user.mobileNo ?? "-"} ",
// "Employee ID: ${userType == "user" ? user.userId : user.travellerId}",
style: GoogleFonts.poppins(
fontSize: 10,
color: isSelected ? widget.layoutColorForUser : Colors.black,
),
),
onTap: () {
@ -514,8 +555,8 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
);
},
),
)
: SizedBox.shrink(),
),
// : SizedBox.shrink(),
// Traveler Form
if (_showTravellerForm)
@ -575,30 +616,30 @@ class _UserSelectionDialogState extends State<UserSelectionDialog> {
SizedBox(width: 10),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: widget.layoutColorForUser,
backgroundColor: isValid ? widget.layoutColorForUser : Colors.grey,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(
color: widget.layoutColorForUser,
width: 2,
// color: widget.layoutColorForUser,
color: isValid ? widget.layoutColorForUser : Colors.grey,
width: isValid ? 2 : 0,
),
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
),
onPressed: () {
print(
"Submitting: ${_searchController.text}, ID: $userIdSelected",
);
widget.onSubmit(
_searchController.text,
userIdSelected,
isTraveller,
);
Navigator.pop(context);
},
onPressed: isValid ? () {
print("Submitting: ${_searchController.text}, ID: $userIdSelected");
widget.onSubmit(
_searchController.text,
userIdSelected,
isTraveller,
);
Navigator.pop(context);
}
: null,
child: Text(
"Submit",
"Save",
style: GoogleFonts.poppins(fontSize: 11),
),
),

View File

@ -277,6 +277,7 @@ class _AccomodationScreenState extends State<AccomodationScreen> {
List<String> requiredFields = [
"destination_city",
"hotel_name",
"class",
"checkin_date",
"checkin_time",
"checkout_date",

View File

@ -649,6 +649,9 @@ class FlightScreenState extends State<FlightScreen> {
errorMessages["date_$i"] = "Required";
}
if( selectedClasses[i] == null ) {
errorMessages["class_$i"] = "Required";
}
if (textControllers["_time${i}Controller"]?.text.trim().isEmpty ?? true) {
errorMessages["time_$i"] = "Required";
}