Added quote expiry-aware flows with auto-refresh
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/quotation.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
@@ -17,6 +18,7 @@ class PaymentAmountWidget extends StatefulWidget {
|
||||
|
||||
class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
late final TextEditingController _controller;
|
||||
late final FocusNode _focusNode;
|
||||
bool _isSyncingText = false;
|
||||
|
||||
@override
|
||||
@@ -24,10 +26,13 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
super.initState();
|
||||
final initialAmount = context.read<PaymentAmountProvider>().amount;
|
||||
_controller = TextEditingController(text: amountToString(initialAmount));
|
||||
_focusNode = FocusNode()..addListener(_handleFocusChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.removeListener(_handleFocusChange);
|
||||
_focusNode.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -56,6 +61,14 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleFocusChange() {
|
||||
if (_focusNode.hasFocus) return;
|
||||
final quotationProvider = context.read<QuotationProvider>();
|
||||
if (quotationProvider.canRequestQuote) {
|
||||
quotationProvider.refreshNow(force: false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amount = context.select<PaymentAmountProvider, double>((provider) => provider.amount);
|
||||
@@ -63,6 +76,7 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.amount,
|
||||
|
||||
Reference in New Issue
Block a user