fixes
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
|
||||
|
||||
String walletBalance(Wallet wallet) {
|
||||
final symbol = currencyCodeToSymbol(wallet.currency);
|
||||
return '$symbol ${amountToString(wallet.balance)}';
|
||||
String walletBalance(BuildContext context, Wallet wallet) {
|
||||
return formatMoneyUi(
|
||||
context,
|
||||
Money(
|
||||
amount: amountToString(wallet.balance),
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String ledgerBalance(LedgerAccount account) {
|
||||
String ledgerBalance(BuildContext context, LedgerAccount account) {
|
||||
final money = account.balance?.balance;
|
||||
final rawAmount = money?.amount.trim();
|
||||
final amount = parseMoneyAmount(rawAmount, fallback: double.nan);
|
||||
final amountText = amount.isNaN
|
||||
? (rawAmount == null || rawAmount.isEmpty ? '--' : rawAmount)
|
||||
: amountToString(amount);
|
||||
final effectiveCurrency = (money?.currency.trim().isNotEmpty ?? false)
|
||||
? money!.currency
|
||||
: account.currency;
|
||||
|
||||
final currencyCode = (money?.currency ?? account.currency)
|
||||
.trim()
|
||||
.toUpperCase();
|
||||
final symbol = currencySymbolFromCode(currencyCode);
|
||||
if (symbol != null && symbol.trim().isNotEmpty) {
|
||||
return '$symbol $amountText';
|
||||
}
|
||||
if (currencyCode.isNotEmpty) {
|
||||
return '$amountText $currencyCode';
|
||||
}
|
||||
return amountText;
|
||||
return formatMoneyUi(
|
||||
context,
|
||||
Money(amount: money?.amount ?? '', currency: effectiveCurrency),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
|
||||
required BuildContext context,
|
||||
required List<Wallet> wallets,
|
||||
required List<LedgerAccount> ledgerAccounts,
|
||||
required AppLocalizations l10n,
|
||||
@@ -20,7 +21,7 @@ List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
|
||||
return DropdownMenuItem<SourceOptionKey>(
|
||||
value: walletOptionKey(wallet.id),
|
||||
child: Text(
|
||||
'${walletDisplayName(wallet, l10n)} - ${walletBalance(wallet)}',
|
||||
'${walletDisplayName(wallet, l10n)} - ${walletBalance(context, wallet)}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
@@ -29,7 +30,7 @@ List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
|
||||
return DropdownMenuItem<SourceOptionKey>(
|
||||
value: ledgerOptionKey(ledger.ledgerAccountRef),
|
||||
child: Text(
|
||||
'${ledgerDisplayName(ledger, l10n)} - ${ledgerBalance(ledger)}',
|
||||
'${ledgerDisplayName(ledger, l10n)} - ${ledgerBalance(context, ledger)}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ Widget buildSourceSelectorField({
|
||||
}
|
||||
|
||||
final items = buildSourceSelectorItems(
|
||||
context: context,
|
||||
wallets: wallets,
|
||||
ledgerAccounts: ledgerAccounts,
|
||||
l10n: l10n,
|
||||
|
||||
Reference in New Issue
Block a user