small fixes for single payout and big chunck for multiple payouts
This commit is contained in:
@@ -158,6 +158,28 @@ class PaymentsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addPayments(List<Payment> items, {bool prepend = true}) {
|
||||
if (items.isEmpty) return;
|
||||
final current = List<Payment>.from(payments);
|
||||
final existingRefs = <String>{};
|
||||
for (final payment in current) {
|
||||
final ref = payment.paymentRef;
|
||||
if (ref != null && ref.isNotEmpty) {
|
||||
existingRefs.add(ref);
|
||||
}
|
||||
}
|
||||
|
||||
final newItems = items.where((payment) {
|
||||
final ref = payment.paymentRef;
|
||||
if (ref == null || ref.isEmpty) return true;
|
||||
return !existingRefs.contains(ref);
|
||||
}).toList();
|
||||
|
||||
if (newItems.isEmpty) return;
|
||||
final combined = prepend ? [...newItems, ...current] : [...current, ...newItems];
|
||||
_applyResource(_resource.copyWith(data: combined, error: null), notify: true);
|
||||
}
|
||||
|
||||
void _applyResource(Resource<List<Payment>> newResource, {required bool notify}) {
|
||||
_resource = newResource;
|
||||
if (notify) notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user