added infinite loading
This commit is contained in:
parent
b0c9a2c45f
commit
754f919cdc
@ -32,7 +32,7 @@ class ExpenseController extends GetxController {
|
||||
final RxList<EmployeeModel> selectedCreatedByEmployees =
|
||||
<EmployeeModel>[].obs;
|
||||
final RxString selectedDateType = 'Transaction Date'.obs;
|
||||
|
||||
|
||||
final employeeSearchController = TextEditingController();
|
||||
final isSearchingEmployees = false.obs;
|
||||
final employeeSearchResults = <EmployeeModel>[].obs;
|
||||
@ -283,6 +283,42 @@ class ExpenseController extends GetxController {
|
||||
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
|
||||
Future<bool> updateExpenseStatus(String expenseId, String statusId) async {
|
||||
isLoading.value = true;
|
||||
|
@ -90,7 +90,8 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
||||
),
|
||||
Expanded(
|
||||
child: Obx(() {
|
||||
if (expenseController.isLoading.value) {
|
||||
if (expenseController.isLoading.value &&
|
||||
expenseController.expenses.isEmpty) {
|
||||
return SkeletonLoaders.expenseListSkeletonLoader();
|
||||
}
|
||||
|
||||
@ -104,9 +105,20 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen> {
|
||||
}
|
||||
|
||||
final filteredList = _getFilteredExpenses();
|
||||
return ExpenseList(
|
||||
expenseList: filteredList,
|
||||
onViewDetail: () => expenseController.fetchExpenses(),
|
||||
|
||||
return NotificationListener<ScrollNotification>(
|
||||
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
|
||||
floatingActionButton: permissionController
|
||||
.hasPermission(Permissions.expenseUpload)
|
||||
? FloatingActionButton(
|
||||
backgroundColor: Colors.red,
|
||||
onPressed: showAddExpenseBottomSheet,
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
)
|
||||
: null,
|
||||
floatingActionButton:
|
||||
permissionController.hasPermission(Permissions.expenseUpload)
|
||||
? FloatingActionButton(
|
||||
backgroundColor: Colors.red,
|
||||
onPressed: showAddExpenseBottomSheet,
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user