WIP: integration with ledger
This commit is contained in:
33
frontend/pshared/lib/provider/payment/source.dart
Normal file
33
frontend/pshared/lib/provider/payment/source.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/models/payment/source.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
|
||||
class PaymentSourceProvider extends ChangeNotifier {
|
||||
List<PaymentSource> _sources = const [];
|
||||
|
||||
List<PaymentSource> get sources => _sources;
|
||||
|
||||
void update(
|
||||
WalletsProvider walletsProvider,
|
||||
LedgerAccountsProvider ledgerProvider,
|
||||
) {
|
||||
final nextSources = <PaymentSource>[
|
||||
...walletsProvider.wallets.map(PaymentSource.wallet),
|
||||
...ledgerProvider.accounts.map(PaymentSource.ledger),
|
||||
];
|
||||
|
||||
final currentKeys = _sources
|
||||
.map((source) => source.key)
|
||||
.toList(growable: false);
|
||||
final nextKeys = nextSources
|
||||
.map((source) => source.key)
|
||||
.toList(growable: false);
|
||||
|
||||
if (listEquals(currentKeys, nextKeys)) return;
|
||||
|
||||
_sources = nextSources;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user