refactoring for recipient addition page

This commit is contained in:
Arseni
2026-01-29 19:22:30 +03:00
parent da8da04ae9
commit efa69b43b2
47 changed files with 1376 additions and 532 deletions

View File

@@ -9,6 +9,7 @@ import 'package:pweb/pages/address_book/page/search.dart';
import 'package:pweb/pages/dashboard/payouts/single/address_book/long_list/widget.dart';
import 'package:pweb/pages/dashboard/payouts/single/address_book/placeholder.dart';
import 'package:pweb/pages/dashboard/payouts/single/address_book/short_list.dart';
import 'package:pweb/utils/recipient/filtering.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
@@ -34,18 +35,14 @@ class _AddressBookPayoutState extends State<AddressBookPayout> {
final FocusNode _searchFocusNode = FocusNode();
late final TextEditingController _searchController;
String _query = '';
bool get _isExpanded => _searchFocusNode.hasFocus;
@override
void initState() {
super.initState();
final provider = context.read<RecipientsProvider>();
_searchController = TextEditingController(text: provider.query);
_searchController.addListener(() {
provider.setQuery(_searchController.text);
});
_searchController = TextEditingController();
}
@override
@@ -55,12 +52,21 @@ class _AddressBookPayoutState extends State<AddressBookPayout> {
super.dispose();
}
void _setQuery(String query) {
setState(() {
_query = query;
});
}
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
final provider = context.watch<RecipientsProvider>();
final recipients = provider.recipients;
final filteredRecipients = provider.filteredRecipients;
final filteredRecipients = filterRecipients(
recipients: recipients,
query: _query,
);
if (provider.isLoading) {
return const Center(child: CircularProgressIndicator());
@@ -86,7 +92,7 @@ class _AddressBookPayoutState extends State<AddressBookPayout> {
RecipientSearchField(
controller: _searchController,
focusNode: _searchFocusNode,
onChanged: (_) {},
onChanged: _setQuery,
),
const SizedBox(height: _spacingBetween),
Expanded(
@@ -110,4 +116,4 @@ class _AddressBookPayoutState extends State<AddressBookPayout> {
),
);
}
}
}

View File

@@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:pshared/models/payment/type.dart';
import 'package:pweb/models/control_state.dart';
import 'package:pweb/pages/dashboard/payouts/single/new_recipient/type.dart';
import 'package:pweb/utils/payment/availability.dart';
class SinglePayout extends StatelessWidget {
@@ -17,7 +19,7 @@ class SinglePayout extends StatelessWidget {
@override
Widget build(BuildContext context) {
final paymentTypes = PaymentType.values;
final paymentTypes = visiblePaymentTypes;
final dividerColor = Theme.of(context).dividerColor;
return SizedBox(
@@ -36,6 +38,9 @@ class SinglePayout extends StatelessWidget {
PaymentTypeTile(
type: paymentTypes[i],
onSelected: onGoToPayment,
state: disabledPaymentTypes.contains(paymentTypes[i])
? ControlState.disabled
: ControlState.enabled,
),
if (i < paymentTypes.length - 1)
Padding(

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:pshared/models/payment/type.dart';
import 'package:pweb/models/control_state.dart';
import 'package:pweb/pages/payment_methods/icon.dart';
import 'package:pweb/utils/payment/label.dart';
@@ -9,30 +10,53 @@ import 'package:pweb/utils/payment/label.dart';
class PaymentTypeTile extends StatelessWidget {
final PaymentType type;
final void Function(PaymentType type) onSelected;
final ControlState state;
const PaymentTypeTile({
super.key,
required this.type,
required this.onSelected,
this.state = ControlState.enabled,
});
@override
Widget build(BuildContext context) {
final label = getPaymentTypeLabel(context, type);
final theme = Theme.of(context);
final isEnabled = state == ControlState.enabled;
final isDisabled = state == ControlState.disabled;
final isLoading = state == ControlState.loading;
final textColor = isDisabled
? theme.colorScheme.onSurface.withValues(alpha: 0.55)
: theme.colorScheme.onSurface;
return InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () => onSelected(type),
onTap: isEnabled ? () => onSelected(type) : null,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Icon(iconForPaymentType(type), size: 24),
Icon(iconForPaymentType(type), size: 24, color: textColor),
const SizedBox(width: 12),
Text(
label,
style: Theme.of(context).textTheme.bodyMedium,
style: theme.textTheme.bodyMedium?.copyWith(color: textColor),
),
if (isLoading) ...[
const SizedBox(width: 12),
SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
theme.colorScheme.primary,
),
),
),
],
],
),
),