added comment for payment, changed intent and added amount ui in operations
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/models/payment/amount/mode.dart';
|
||||
|
||||
|
||||
class PaymentAmountFieldController extends ChangeNotifier {
|
||||
static const String _settlementCurrencyCode = 'RUB';
|
||||
|
||||
@@ -19,9 +20,9 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
bool _isSyncingText = false;
|
||||
PaymentAmountMode _mode = PaymentAmountMode.debit;
|
||||
|
||||
PaymentAmountFieldController({required double initialAmount})
|
||||
PaymentAmountFieldController({required double? initialAmount})
|
||||
: textController = TextEditingController(
|
||||
text: amountToString(initialAmount),
|
||||
text: initialAmount == null ? '' : amountToString(initialAmount),
|
||||
);
|
||||
|
||||
PaymentAmountMode get mode => _mode;
|
||||
@@ -57,9 +58,7 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
void handleChanged(String value) {
|
||||
if (_isSyncingText) return;
|
||||
final parsed = _parseAmount(value);
|
||||
if (parsed != null) {
|
||||
_provider?.setAmount(parsed);
|
||||
}
|
||||
_provider?.setAmount(parsed);
|
||||
}
|
||||
|
||||
void handleModeChanged(PaymentAmountMode value) {
|
||||
@@ -130,11 +129,11 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
return parsed.isNaN ? null : parsed;
|
||||
}
|
||||
|
||||
void _syncTextWithAmount(double amount) {
|
||||
void _syncTextWithAmount(double? amount) {
|
||||
final parsedText = _parseAmount(textController.text);
|
||||
if (parsedText != null && parsedText == amount) return;
|
||||
if (parsedText == amount) return;
|
||||
|
||||
final nextText = amountToString(amount);
|
||||
final nextText = amount == null ? '' : amountToString(amount);
|
||||
_isSyncingText = true;
|
||||
textController.value = TextEditingValue(
|
||||
text: nextText,
|
||||
|
||||
53
frontend/pweb/lib/controllers/payments/comment_field.dart
Normal file
53
frontend/pweb/lib/controllers/payments/comment_field.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
|
||||
|
||||
class PaymentCommentFieldController extends ChangeNotifier {
|
||||
final TextEditingController textController;
|
||||
|
||||
PaymentAmountProvider? _provider;
|
||||
bool _isSyncingText = false;
|
||||
|
||||
PaymentCommentFieldController({required String initialComment})
|
||||
: textController = TextEditingController(text: initialComment);
|
||||
|
||||
void update(PaymentAmountProvider provider) {
|
||||
if (identical(_provider, provider)) {
|
||||
_syncTextWithComment(provider.comment);
|
||||
return;
|
||||
}
|
||||
_provider?.removeListener(_handleProviderChanged);
|
||||
_provider = provider;
|
||||
_provider?.addListener(_handleProviderChanged);
|
||||
_syncTextWithComment(provider.comment);
|
||||
}
|
||||
|
||||
void handleChanged(String value) {
|
||||
if (_isSyncingText) return;
|
||||
_provider?.setComment(value);
|
||||
}
|
||||
|
||||
void _handleProviderChanged() {
|
||||
final provider = _provider;
|
||||
if (provider == null) return;
|
||||
_syncTextWithComment(provider.comment);
|
||||
}
|
||||
|
||||
void _syncTextWithComment(String comment) {
|
||||
if (textController.text == comment) return;
|
||||
_isSyncingText = true;
|
||||
textController.value = TextEditingValue(
|
||||
text: comment,
|
||||
selection: TextSelection.collapsed(offset: comment.length),
|
||||
);
|
||||
_isSyncingText = false;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_provider?.removeListener(_handleProviderChanged);
|
||||
textController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/provider.dart';
|
||||
import 'package:pshared/provider/payment/quotation/quotation.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
@@ -14,6 +15,7 @@ class PaymentPageController extends ChangeNotifier {
|
||||
PaymentProvider? _payment;
|
||||
QuotationProvider? _quotation;
|
||||
PaymentFlowProvider? _flow;
|
||||
PaymentAmountProvider? _amount;
|
||||
RecipientsProvider? _recipients;
|
||||
|
||||
bool _isSending = false;
|
||||
@@ -26,11 +28,13 @@ class PaymentPageController extends ChangeNotifier {
|
||||
PaymentProvider payment,
|
||||
QuotationProvider quotation,
|
||||
PaymentFlowProvider flow,
|
||||
PaymentAmountProvider amount,
|
||||
RecipientsProvider recipients,
|
||||
) {
|
||||
_payment = payment;
|
||||
_quotation = quotation;
|
||||
_flow = flow;
|
||||
_amount = amount;
|
||||
_recipients = recipients;
|
||||
}
|
||||
|
||||
@@ -59,6 +63,7 @@ class PaymentPageController extends ChangeNotifier {
|
||||
_quotation?.reset();
|
||||
_payment?.reset();
|
||||
_flow?.setManualPaymentData(null);
|
||||
_amount?.setComment('');
|
||||
_recipients?.setCurrentObject(null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user