added infinite loading
This commit is contained in:
parent
b0c9a2c45f
commit
754f919cdc
@ -32,7 +32,7 @@ class ExpenseController extends GetxController {
|
|||||||
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
||||||
<EmployeeModel>[].obs;
|
<EmployeeModel>[].obs;
|
||||||
final RxString selectedDateType = 'Transaction Date'.obs;
|
final RxString selectedDateType = 'Transaction Date'.obs;
|
||||||
|
|
||||||
final employeeSearchController = TextEditingController();
|
final employeeSearchController = TextEditingController();
|
||||||
final isSearchingEmployees = false.obs;
|
final isSearchingEmployees = false.obs;
|
||||||
final employeeSearchResults = <EmployeeModel>[].obs;
|
final employeeSearchResults = <EmployeeModel>[].obs;
|
||||||
@ -283,6 +283,42 @@ class ExpenseController extends GetxController {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> loadMoreExpenses() async {
|
||||||
|
if (isLoading.value) return;
|
||||||
|
|
||||||
|
_pageNumber += 1;
|
||||||
|
isLoading.value = true;
|
||||||
|
|
||||||
|
final Map<String, dynamic> filterMap = {
|
||||||
|
"projectIds": selectedProject.value.isEmpty
|
||||||
|
? []
|
||||||
|
: [projectsMap[selectedProject.value] ?? ''],
|
||||||
|
"statusIds": selectedStatus.value.isEmpty ? [] : [selectedStatus.value],
|
||||||
|
"createdByIds": selectedCreatedByEmployees.map((e) => e.id).toList(),
|
||||||
|
"paidByIds": selectedPaidByEmployees.map((e) => e.id).toList(),
|
||||||
|
"startDate": startDate.value?.toIso8601String(),
|
||||||
|
"endDate": endDate.value?.toIso8601String(),
|
||||||
|
"isTransactionDate": selectedDateType.value == 'Transaction Date',
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
final result = await ApiService.getExpenseListApi(
|
||||||
|
filter: jsonEncode(filterMap),
|
||||||
|
pageSize: _pageSize,
|
||||||
|
pageNumber: _pageNumber,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
final expenseResponse = ExpenseResponse.fromJson(result);
|
||||||
|
expenses.addAll(expenseResponse.data.data);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logSafe("Error in loadMoreExpenses: $e", level: LogLevel.error);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Update expense status
|
/// Update expense status
|
||||||
Future<bool> updateExpenseStatus(String expenseId, String statusId) async {
|
Future<bool> updateExpenseStatus(String expenseId, String statusId) async {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
|||||||
@ -90,7 +90,8 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
if (expenseController.isLoading.value) {
|
if (expenseController.isLoading.value &&
|
||||||
|
expenseController.expenses.isEmpty) {
|
||||||
return SkeletonLoaders.expenseListSkeletonLoader();
|
return SkeletonLoaders.expenseListSkeletonLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +105,20 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final filteredList = _getFilteredExpenses();
|
final filteredList = _getFilteredExpenses();
|
||||||
return ExpenseList(
|
|
||||||
expenseList: filteredList,
|
return NotificationListener<ScrollNotification>(
|
||||||
onViewDetail: () => expenseController.fetchExpenses(),
|
onNotification: (ScrollNotification scrollInfo) {
|
||||||
|
if (scrollInfo.metrics.pixels ==
|
||||||
|
scrollInfo.metrics.maxScrollExtent &&
|
||||||
|
!expenseController.isLoading.value) {
|
||||||
|
expenseController.loadMoreExpenses();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
child: ExpenseList(
|
||||||
|
expenseList: filteredList,
|
||||||
|
onViewDetail: () => expenseController.fetchExpenses(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@ -115,14 +127,14 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
|||||||
),
|
),
|
||||||
|
|
||||||
// ✅ FAB only if user has expenseUpload permission
|
// ✅ FAB only if user has expenseUpload permission
|
||||||
floatingActionButton: permissionController
|
floatingActionButton:
|
||||||
.hasPermission(Permissions.expenseUpload)
|
permissionController.hasPermission(Permissions.expenseUpload)
|
||||||
? FloatingActionButton(
|
? FloatingActionButton(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
onPressed: showAddExpenseBottomSheet,
|
onPressed: showAddExpenseBottomSheet,
|
||||||
child: const Icon(Icons.add, color: Colors.white),
|
child: const Icon(Icons.add, color: Colors.white),
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user