refactoring for recipient addition page
This commit is contained in:
26
frontend/pweb/lib/utils/payment/availability.dart
Normal file
26
frontend/pweb/lib/utils/payment/availability.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
const List<PaymentType> enabledPaymentTypes = [
|
||||
PaymentType.card,
|
||||
PaymentType.ledger,
|
||||
PaymentType.externalChain,
|
||||
];
|
||||
|
||||
const List<PaymentType> previewPaymentTypes = [
|
||||
PaymentType.bankAccount,
|
||||
];
|
||||
|
||||
const List<PaymentType> visiblePaymentTypes = [
|
||||
...enabledPaymentTypes,
|
||||
...previewPaymentTypes,
|
||||
];
|
||||
|
||||
const Set<PaymentType> disabledPaymentTypes = {
|
||||
PaymentType.bankAccount,
|
||||
};
|
||||
|
||||
MethodMap filterVisiblePaymentTypes(MethodMap source) => {
|
||||
for (final type in visiblePaymentTypes)
|
||||
if (source.containsKey(type)) type: source[type],
|
||||
};
|
||||
@@ -10,12 +10,14 @@ class PaymentTypeSelector extends StatelessWidget {
|
||||
final MethodMap availableTypes;
|
||||
final PaymentType selectedType;
|
||||
final ValueChanged<PaymentType> onSelected;
|
||||
final Set<PaymentType> disabledTypes;
|
||||
|
||||
const PaymentTypeSelector({
|
||||
super.key,
|
||||
required this.availableTypes,
|
||||
required this.selectedType,
|
||||
required this.onSelected,
|
||||
this.disabledTypes = const {},
|
||||
});
|
||||
|
||||
static const double _chipSpacing = 12.0;
|
||||
@@ -30,14 +32,16 @@ class PaymentTypeSelector extends StatelessWidget {
|
||||
runSpacing: _chipSpacing,
|
||||
children: availableTypes.keys.map((type) {
|
||||
final isSelected = selectedType == type;
|
||||
final isDisabled = disabledTypes.contains(type);
|
||||
final labelColor = isSelected
|
||||
? theme.colorScheme.onPrimary
|
||||
: theme.colorScheme.onSurface.withValues(alpha: isDisabled ? 0.55 : 1.0);
|
||||
|
||||
return ChoiceChip(
|
||||
label: Text(
|
||||
getPaymentTypeLabel(context, type),
|
||||
style: theme.textTheme.titleMedium!.copyWith(
|
||||
color: isSelected
|
||||
? theme.colorScheme.onPrimary
|
||||
: theme.colorScheme.onSurface,
|
||||
color: labelColor,
|
||||
),
|
||||
),
|
||||
selected: isSelected,
|
||||
@@ -47,7 +51,7 @@ class PaymentTypeSelector extends StatelessWidget {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(_chipBorderRadius),
|
||||
),
|
||||
onSelected: (_) => onSelected(type),
|
||||
onSelected: isDisabled ? null : (_) => onSelected(type),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user