This commit is contained in:
venbaittech 2025-12-26 16:48:54 +05:30
parent 9f3b22200f
commit 02e73e3543
3 changed files with 224 additions and 193 deletions

View File

@ -60,7 +60,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
dropDownKeyPartner = GlobalKey<DropdownSearchState<Map<String, dynamic>>>();
late ApiService apiService;
List<dynamic>? selectedPartnerIds = [];
// List<dynamic>? selectedPartnerIds = [];
List<Map<String, dynamic>> getPartnerData = [];
List<Map<String, dynamic>> filteredPartnerData = [];
@ -88,10 +88,10 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
final userID = ref.watch(userIdProvider);
role = ref.watch(userRoleProvider);
print("managerId - $managerId");
if (userID != null && role != null) {
print('hansles');
getPartnerDetails(userID);
}
// if (userID != null && role != null) {
// print('hansles');
// getPartnerDetails(userID);
// }
if (managerId != null) {
print('managerId - $managerId');
@ -165,40 +165,40 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
}
}
Future<void> getPartnerDetails(int id) async {
print('getPartnerDetails called By handler');
setState(() {
isLoading = true;
});
try {
// final response = await apiService.fetchStaffUserList(id, role);
final response = await apiService.fetchStaffListForEnquiryAssignDropDown(
managerId,
id,
role,
);
if (response['status'] == 'success') {
print('getStaffDetails - ${response['data']}');
setState(() {
getPartnerData = List<Map<String, dynamic>>.from(response['data']);
print('API Data - $getPartnerData');
filteredPartnerData = List.from(getPartnerData);
print('originalData - $filteredPartnerData');
});
} else {
getPartnerData = [];
filteredPartnerData = [];
}
} catch (e) {
print('Exception occurred: $e');
} finally {
setState(() {
isLoading = false;
});
}
}
// Future<void> getPartnerDetails(int id) async {
// print('getPartnerDetails called By handler');
// setState(() {
// isLoading = true;
// });
//
// try {
// // final response = await apiService.fetchStaffUserList(id, role);
// final response = await apiService.fetchStaffListForEnquiryAssignDropDown(
// managerId,
// id,
// role,
// );
// if (response['status'] == 'success') {
// print('getStaffDetails - ${response['data']}');
// setState(() {
// getPartnerData = List<Map<String, dynamic>>.from(response['data']);
// print('API Data - $getPartnerData');
//
// filteredPartnerData = List.from(getPartnerData);
// print('originalData - $filteredPartnerData');
// });
// } else {
// getPartnerData = [];
// filteredPartnerData = [];
// }
// } catch (e) {
// print('Exception occurred: $e');
// } finally {
// setState(() {
// isLoading = false;
// });
// }
// }
@override
Widget build(BuildContext context) {
@ -350,7 +350,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
return null; // no error
},
controller: widget.endController,
lastDate: DateTime.now(),
// lastDate: DateTime.now(),
onDateSelected: (date) {
print("Picked Date: $date");
widget.endController.text = DateFormat('dd-MM-yyyy').format(date);
@ -536,9 +536,15 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
// : null,
selectedItems: filteredPartnerData
.where(
(item) => (selectedPartnerIds ?? []).contains(item['id']),
(item) => (widget.selectedParnter ?? []).contains(item['id']),
)
.toList(),
// selectedItems: filteredPartnerData
// .where(
// (item) => (selectedPartnerIds ?? []).contains(item['id']),
// )
// .toList(),
items: (filter, infiniteScrollProps) {
return filteredPartnerData;
},
@ -647,7 +653,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
// .map((v) => v['id'].toString())
// .toList();
final ids = selectedVals.map((v) => v['id'].toString()).toList();
print("Selected PArnter IDs: $selectedPartnerIds");
print("Selected PArnter IDs: $widget.selectedPartnerIds");
widget.onPartnerChanges?.call(ids);
// widget.onPartnerChanges!(v['id']);
},
@ -657,153 +663,153 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
);
}
Widget buildSelectStaffMem(BuildContext context) {
Map<String, dynamic>? selectedVehicle;
if (widget.selectedStaffId == null) {
selectedVehicle = null;
} else if (widget.selectedStaffId != null) {
selectedVehicle = filteredPartnerData.firstWhere(
(item) => item['id'] == widget.selectedStaffId,
orElse: () => {}, // empty map
);
if (selectedVehicle.isEmpty) selectedVehicle = null;
} else if (selectedStaff != null) {
selectedVehicle = filteredPartnerData.firstWhere(
(item) => item['id'] == selectedStaff,
orElse: () => {}, // empty map
);
if (selectedVehicle.isEmpty) selectedVehicle = null;
} else {
selectedVehicle = null;
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Text("Staff Name", style: _textStyle),
// SizedBox(height: 10),
SizedBox(
height: 35,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
border: Border.all(color: Color(0xFFE2E8F0)),
// color: Colors.black,
),
width: ResponsiveLayout.isMobile(context)
? null
: MediaQuery.of(context).size.width * 0.13,
// height: 45,
child: DropdownSearch<Map<String, dynamic>>(
// key: dropDownKey,
key: ValueKey(selectedStaff),
// selectedItem: selectedVehicle.isNotEmpty ? selectedVehicle : null,
selectedItem: selectedVehicle,
items: (filter, infiniteScrollProps) {
return filteredPartnerData;
},
itemAsString: (val) => val['name'].toString(),
compareFn: (item, selectedItem) =>
item['id'] == selectedItem['id'], // compare by id
dropdownBuilder: (context, selectedItem) => Align(
alignment: Alignment.centerLeft,
child: Text(
selectedItem != null ? selectedItem['name'].toString() : "",
style: GoogleFonts.poppins(fontSize: 11, color: Colors.black),
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: false,
),
),
decoratorProps: DropDownDecoratorProps(
decoration:
AppInputDecorations.dropdownDecoration(
label: "Select Staff ",
).copyWith(
filled: true,
fillColor:
Colors.white, // 👈 makes the dropdown input white
contentPadding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 1, // 👈 adjust this to make the field shorter
),
),
),
popupProps: PopupProps.menu(
fit: FlexFit.loose,
constraints: BoxConstraints(maxHeight: 250),
menuProps: MenuProps(
backgroundColor:
Colors.white, // 👈 sets dropdown background to white
),
showSearchBox: true,
searchFieldProps: TextFieldProps(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: "Search Staff ...",
hintStyle: GoogleFonts.inter(
fontSize: 12,
color: Colors.black,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
), // 👈 Normal border
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 1.5,
), // 👈 Focused border
),
),
),
itemBuilder: (context, item, isDisabled, isSelected) {
return Container(
// color: isSelected ? Colors.blue.withOpacity(0.1) : null,
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
child: Text(
item['name'].toString(),
style: GoogleFonts.inter(
fontSize: 13,
color: Colors.black,
),
),
);
},
// constraints: BoxConstraints(),
),
onChanged: (val) {
if (val != null) {
print("Selected Staff : ${val['name']}");
print("Id: ${val['id']}");
// selectedStaffName = val['name'];
// selectedStaff = val['id'];
widget.onBrokerChanged!(val['id']);
// if (widget.onFilterStaff != null)
// widget.onFilterStaff!(val['id']);
// Future.microtask(() => widget.onFilter());
// controllers['agentId']?.text = val['agent_code'];
// agentId = agent['id'];
}
},
),
),
),
],
);
}
// Widget buildSelectStaffMem(BuildContext context) {
// Map<String, dynamic>? selectedVehicle;
// if (widget.selectedStaffId == null) {
// selectedVehicle = null;
// } else if (widget.selectedStaffId != null) {
// selectedVehicle = filteredPartnerData.firstWhere(
// (item) => item['id'] == widget.selectedStaffId,
// orElse: () => {}, // empty map
// );
// if (selectedVehicle.isEmpty) selectedVehicle = null;
// } else if (selectedStaff != null) {
// selectedVehicle = filteredPartnerData.firstWhere(
// (item) => item['id'] == selectedStaff,
// orElse: () => {}, // empty map
// );
// if (selectedVehicle.isEmpty) selectedVehicle = null;
// } else {
// selectedVehicle = null;
// }
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// // Text("Staff Name", style: _textStyle),
// // SizedBox(height: 10),
// SizedBox(
// height: 35,
// child: Container(
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(5.0),
// border: Border.all(color: Color(0xFFE2E8F0)),
// // color: Colors.black,
// ),
//
// width: ResponsiveLayout.isMobile(context)
// ? null
// : MediaQuery.of(context).size.width * 0.13,
// // height: 45,
// child: DropdownSearch<Map<String, dynamic>>(
// // key: dropDownKey,
// key: ValueKey(selectedStaff),
// // selectedItem: selectedVehicle.isNotEmpty ? selectedVehicle : null,
// selectedItem: selectedVehicle,
//
// items: (filter, infiniteScrollProps) {
// return filteredPartnerData;
// },
//
// itemAsString: (val) => val['name'].toString(),
// compareFn: (item, selectedItem) =>
// item['id'] == selectedItem['id'], // compare by id
// dropdownBuilder: (context, selectedItem) => Align(
// alignment: Alignment.centerLeft,
// child: Text(
// selectedItem != null ? selectedItem['name'].toString() : "",
// style: GoogleFonts.poppins(fontSize: 11, color: Colors.black),
// overflow: TextOverflow.ellipsis,
// maxLines: 1,
// softWrap: false,
// ),
// ),
// decoratorProps: DropDownDecoratorProps(
// decoration:
// AppInputDecorations.dropdownDecoration(
// label: "Select Staff ",
// ).copyWith(
// filled: true,
// fillColor:
// Colors.white, // 👈 makes the dropdown input white
// contentPadding: const EdgeInsets.symmetric(
// horizontal: 6,
// vertical: 1, // 👈 adjust this to make the field shorter
// ),
// ),
// ),
//
// popupProps: PopupProps.menu(
// fit: FlexFit.loose,
// constraints: BoxConstraints(maxHeight: 250),
// menuProps: MenuProps(
// backgroundColor:
// Colors.white, // 👈 sets dropdown background to white
// ),
// showSearchBox: true,
// searchFieldProps: TextFieldProps(
// decoration: InputDecoration(
// filled: true,
// fillColor: Colors.white,
// hintText: "Search Staff ...",
// hintStyle: GoogleFonts.inter(
// fontSize: 12,
// color: Colors.black,
// ),
// enabledBorder: OutlineInputBorder(
// borderSide: BorderSide(
// color: Colors.white,
// ), // 👈 Normal border
// ),
// focusedBorder: OutlineInputBorder(
// borderSide: BorderSide(
// color: Colors.white,
// width: 1.5,
// ), // 👈 Focused border
// ),
// ),
// ),
//
// itemBuilder: (context, item, isDisabled, isSelected) {
// return Container(
// // color: isSelected ? Colors.blue.withOpacity(0.1) : null,
// padding: const EdgeInsets.symmetric(
// horizontal: 8,
// vertical: 3,
// ),
// child: Text(
// item['name'].toString(),
// style: GoogleFonts.inter(
// fontSize: 13,
// color: Colors.black,
// ),
// ),
// );
// },
//
// // constraints: BoxConstraints(),
// ),
//
// onChanged: (val) {
// if (val != null) {
// print("Selected Staff : ${val['name']}");
// print("Id: ${val['id']}");
// // selectedStaffName = val['name'];
// // selectedStaff = val['id'];
// widget.onBrokerChanged!(val['id']);
// // if (widget.onFilterStaff != null)
// // widget.onFilterStaff!(val['id']);
//
// // Future.microtask(() => widget.onFilter());
// // controllers['agentId']?.text = val['agent_code'];
// // agentId = agent['id'];
// }
// },
// ),
// ),
// ),
// ],
// );
// }
static final _textStyle = GoogleFonts.poppins(
fontSize: 11,

View File

@ -226,6 +226,7 @@ class _PayOutScreenState extends ConsumerState<PayOutScreen> {
selectedPolicies = {};
totalPolicies = '';
totalCommission = '';
// dropDownKeyPartner.currentState?.clear();
});
}

View File

@ -542,6 +542,18 @@ class _policyValidationState extends ConsumerState<policyValidation> {
return;
}
final commissionAmount =
controllers["commission_amount"]?.text.trim() ?? '';
if (widget.item?['is_data_accuracy_checked']?.toString() == '0' &&
commissionAmount.isEmpty) {
ToastHelper.showWarningToast(
context,
"Please calculate commission amount",
);
return;
}
if (widget.item?['is_data_accuracy_checked'] == "1") {
ToastHelper.showWarningToast(context, "Data already confirmed");
return;
@ -607,7 +619,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
final endDate = parseDate(controllers["endDate"]?.text);
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
ToastHelper.showWarningToast(
ToastHelper.showErrorToast(
context,
'Start Date cannot be greater than End Date',
);
@ -895,7 +907,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
"Fuel Type ",
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
),
const SizedBox(width: 6),
const SizedBox(height: 6),
DropdownSearch<String>(
key: dropDownKeyFuel,
@ -1043,8 +1055,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
onTap: onTap,
inputFormatters: inputFormatters, // 👈 USE HERE
validator: (val) {
// if (val == null || val.isEmpty) {
// return ""; // 👈 triggers error border, no text
// }
if (!required) {
return null; // skip validation entirely
}
if (val == null || val.isEmpty) {
return ""; // 👈 triggers error border, no text
return ''; // show red border only when required
}
return null;
},
@ -1618,6 +1638,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
],
),
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
child: buildFuelType(context),
@ -1689,6 +1711,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
],
),
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
child: _buildInput(
@ -1762,7 +1786,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: _buildInput(
'Commission Amount *',
controllers['commission_amount']!,
// required: true,
required: false,
keyboardType:
TextInputType.numberWithOptions(
decimal: true,