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