added pagination to group and batch detail screens

This commit is contained in:
2026-06-24 23:19:45 +02:00
parent 263c10d2bb
commit a31e38765d
4 changed files with 1119 additions and 210 deletions

View File

@@ -24,6 +24,7 @@ class BatchScreenModel {
int currentPage = 0;
int totalPages = 0;
int totalElements = 0;
int pageSize = 10;
String searchQuery = '';
String? statusFilter;
String? currencyFilter;
@@ -34,6 +35,7 @@ class BatchScreenModel {
int batchItemsCurrentPage = 0;
int batchItemsTotalPages = 0;
int batchItemsTotalElements = 0;
int batchItemsPageSize = 10;
String batchItemsSearchQuery = '';
String? batchItemsStatusFilter;
String? batchItemsRecipientAccount;
@@ -167,7 +169,7 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<List<GroupBatch>>> listBatches(
String groupId, {
int page = 0,
int size = 20,
int size = 10,
String? search,
String? status,
String? currency,
@@ -248,6 +250,7 @@ class BatchController extends ChangeNotifier {
await listBatches(
groupId,
page: 0,
size: model.pageSize,
search: search,
status: status,
currency: currency,
@@ -261,6 +264,43 @@ class BatchController extends ChangeNotifier {
await listBatches(
groupId,
page: model.currentPage + 1,
size: model.pageSize,
search: model.searchQuery.isNotEmpty ? model.searchQuery : null,
status: model.statusFilter,
currency: model.currencyFilter,
);
}
/// Navigates to a specific page of batches (0-based index).
/// Clears the current list and loads the requested page.
Future<void> goToPage(String groupId, int page) async {
if (model.isLoadingMore) return;
if (page < 0 || page >= model.totalPages) return;
if (page == model.currentPage) return;
// Clear existing batches so listBatches replaces instead of appending
model.batches = [];
model.currentPage = 0;
if (!_disposed) notifyListeners();
await listBatches(
groupId,
page: page,
size: model.pageSize,
search: model.searchQuery.isNotEmpty ? model.searchQuery : null,
status: model.statusFilter,
currency: model.currencyFilter,
);
}
/// Changes the page size for batches and reloads from page 0.
Future<void> setPageSize(String groupId, int size) async {
if (size == model.pageSize) return;
model.pageSize = size;
if (!_disposed) notifyListeners();
// Reload from page 0 with the new size
await searchBatches(
groupId,
search: model.searchQuery.isNotEmpty ? model.searchQuery : null,
status: model.statusFilter,
currency: model.currencyFilter,
@@ -270,7 +310,7 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<List<GroupBatchItem>>> listBatchItems(
String batchId, {
int page = 0,
int size = 20,
int size = 10,
Map<String, String>? filters,
}) async {
if (page == 0) {
@@ -343,6 +383,7 @@ class BatchController extends ChangeNotifier {
await listBatchItems(
batchId,
page: 0,
size: model.batchItemsPageSize,
filters: _buildBatchItemFilters(
search: search,
status: status,
@@ -359,6 +400,7 @@ class BatchController extends ChangeNotifier {
await listBatchItems(
batchId,
page: model.batchItemsCurrentPage + 1,
size: model.batchItemsPageSize,
filters: _buildBatchItemFilters(
search: model.batchItemsSearchQuery.isNotEmpty
? model.batchItemsSearchQuery
@@ -369,6 +411,39 @@ class BatchController extends ChangeNotifier {
);
}
/// Navigates to a specific page of batch items (0-based index).
/// Clears the current list and loads the requested page.
Future<void> goToBatchItemsPage(String batchId, int page) async {
if (model.batchItemsIsLoadingMore) return;
if (page < 0 || page >= model.batchItemsTotalPages) return;
if (page == model.batchItemsCurrentPage) return;
// Clear existing items so listBatchItems replaces instead of appending
model.batchItems = [];
model.batchItemsCurrentPage = 0;
if (!_disposed) notifyListeners();
await listBatchItems(
batchId,
page: page,
size: model.batchItemsPageSize,
filters: _buildBatchItemFilters(
search: model.batchItemsSearchQuery.isNotEmpty
? model.batchItemsSearchQuery
: null,
status: model.batchItemsStatusFilter,
account: model.batchItemsRecipientAccount,
),
);
}
/// Changes the page size for batch items and reloads from page 0.
void setBatchItemsPageSize(int size) {
if (size == model.batchItemsPageSize) return;
model.batchItemsPageSize = size;
if (!_disposed) notifyListeners();
}
/// Builds the filters map for batch items queries from individual params.
Map<String, String>? _buildBatchItemFilters({
String? search,

View File

@@ -8,6 +8,7 @@ import 'package:qpay/screens/groups/models/recipient_group_model.dart';
class GroupScreenModel {
List<RecipientGroup> groups = [];
List<RecipientGroupMember> members = [];
PageableModel? membersPage;
bool isLoading = false;
bool isLoadingMore = false;
String? errorMessage;
@@ -141,6 +142,7 @@ class GroupController extends ChangeNotifier {
'/recipient-groups/members?recipientGroupId=$groupId',
);
final response = _unwrap(raw);
model.membersPage = PageableModel.fromJson(response);
final List<dynamic> content;
if (response is List) {
content = response;