WIP: integration with ledger
This commit is contained in:
@@ -2,12 +2,13 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/models/payment/source.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentAmountWidget extends StatefulWidget {
|
||||
const PaymentAmountWidget({super.key});
|
||||
|
||||
@@ -32,7 +33,8 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
double? _parseAmount(String value) => double.tryParse(value.replaceAll(',', '.'));
|
||||
double? _parseAmount(String value) =>
|
||||
double.tryParse(value.replaceAll(',', '.'));
|
||||
|
||||
void _syncTextWithAmount(double amount) {
|
||||
final parsedText = _parseAmount(_controller.text);
|
||||
@@ -58,14 +60,28 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amount = context.select<PaymentAmountProvider, double>((provider) => provider.amount);
|
||||
final amount = context.select<PaymentAmountProvider, double>(
|
||||
(provider) => provider.amount,
|
||||
);
|
||||
final source = context.watch<PaymentSourceController>().selectedSource;
|
||||
_syncTextWithAmount(amount);
|
||||
final sourceCurrency = switch (source?.type) {
|
||||
null => null,
|
||||
PaymentSourceType.wallet => currencyCodeToString(
|
||||
source!.wallet!.currency,
|
||||
),
|
||||
PaymentSourceType.ledger =>
|
||||
source!.ledgerAccount?.currency.trim().toUpperCase(),
|
||||
};
|
||||
final amountLabel = sourceCurrency == null || sourceCurrency.isEmpty
|
||||
? AppLocalizations.of(context)!.amount
|
||||
: '${AppLocalizations.of(context)!.amount} ($sourceCurrency)';
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.amount,
|
||||
labelText: amountLabel,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
onChanged: _onChanged,
|
||||
|
||||
Reference in New Issue
Block a user