Frontend first draft
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/utils/initials.dart';
|
||||
|
||||
|
||||
class RecipientAvatar extends StatelessWidget {
|
||||
final String name;
|
||||
final String? avatarUrl;
|
||||
final double avatarRadius;
|
||||
final TextStyle? nameStyle;
|
||||
final bool isVisible;
|
||||
|
||||
static const double _verticalSpacing = 5;
|
||||
|
||||
const RecipientAvatar({
|
||||
super.key,
|
||||
required this.name,
|
||||
this.avatarUrl,
|
||||
required this.avatarRadius,
|
||||
this.nameStyle,
|
||||
required this.isVisible,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textColor = Theme.of(context).colorScheme.onPrimary;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: avatarRadius,
|
||||
backgroundImage: avatarUrl != null ? NetworkImage(avatarUrl!) : null,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
child: avatarUrl == null
|
||||
? Text(
|
||||
getInitials(name),
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: avatarRadius * 0.8,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: _verticalSpacing),
|
||||
if (isVisible)
|
||||
Text(
|
||||
name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: nameStyle ?? Theme.of(context).textTheme.bodyMedium?.copyWith(fontSize: 14),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PaymentInfoRow extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
const PaymentInfoRow({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Text(label, style: Theme.of(context).textTheme.bodySmall),
|
||||
const SizedBox(width: 8),
|
||||
Text(value, style: Theme.of(context).textTheme.bodySmall),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/long_list/info_row.dart';
|
||||
import 'package:pweb/utils/payment/label.dart';
|
||||
|
||||
|
||||
class RecipientItem extends StatelessWidget {
|
||||
final Recipient recipient;
|
||||
final VoidCallback onTap;
|
||||
|
||||
static const double _horizontalPadding = 16.0;
|
||||
static const double _verticalPadding = 8.0;
|
||||
static const double _avatarRadius = 20;
|
||||
static const double _spacingWidth = 12;
|
||||
|
||||
const RecipientItem({
|
||||
super.key,
|
||||
required this.recipient,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: _horizontalPadding,
|
||||
vertical: _verticalPadding,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: RecipientAvatar(
|
||||
isVisible: false,
|
||||
name: recipient.name,
|
||||
avatarUrl: recipient.avatarUrl,
|
||||
avatarRadius: _avatarRadius,
|
||||
nameStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
title: Text(recipient.name),
|
||||
subtitle: Text(recipient.email),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: _spacingWidth),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
if (recipient.bank?.accountNumber.isNotEmpty == true)
|
||||
PaymentInfoRow(
|
||||
label: getPaymentTypeLabel(context, PaymentType.bankAccount),
|
||||
value: recipient.bank!.accountNumber,
|
||||
),
|
||||
if (recipient.card?.pan.isNotEmpty == true)
|
||||
PaymentInfoRow(
|
||||
label: getPaymentTypeLabel(context, PaymentType.card),
|
||||
value: recipient.card!.pan,
|
||||
),
|
||||
if (recipient.iban?.iban.isNotEmpty == true)
|
||||
PaymentInfoRow(
|
||||
label: getPaymentTypeLabel(context, PaymentType.iban),
|
||||
value: recipient.iban!.iban,
|
||||
),
|
||||
if (recipient.wallet?.walletId.isNotEmpty == true)
|
||||
PaymentInfoRow(
|
||||
label: getPaymentTypeLabel(context, PaymentType.wallet),
|
||||
value: recipient.wallet!.walletId,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/long_list/item.dart';
|
||||
|
||||
|
||||
class LongListAdressBookPayout extends StatelessWidget {
|
||||
final List<Recipient> filteredRecipients;
|
||||
final ValueChanged<Recipient>? onSelected;
|
||||
|
||||
const LongListAdressBookPayout({
|
||||
super.key,
|
||||
required this.filteredRecipients,
|
||||
this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: filteredRecipients.length,
|
||||
itemBuilder: (context, index) {
|
||||
final recipient = filteredRecipients[index];
|
||||
return RecipientItem(
|
||||
recipient: recipient,
|
||||
onTap: () => onSelected!(recipient),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
|
||||
|
||||
|
||||
class ShortListAdressBookPayout extends StatelessWidget {
|
||||
final List<Recipient> recipients;
|
||||
final ValueChanged<Recipient> onSelected;
|
||||
|
||||
const ShortListAdressBookPayout({
|
||||
super.key,
|
||||
required this.recipients,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
static const double _avatarRadius = 20;
|
||||
static const double _avatarSize = 80;
|
||||
static const EdgeInsets _padding = EdgeInsets.symmetric(horizontal: 10, vertical: 8);
|
||||
static const TextStyle _nameStyle = TextStyle(fontSize: 12);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: recipients.map((recipient) {
|
||||
return Padding(
|
||||
padding: _padding,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
hoverColor: Theme.of(context).colorScheme.primaryContainer,
|
||||
onTap: () => onSelected(recipient),
|
||||
child: SizedBox(
|
||||
height: _avatarSize,
|
||||
width: _avatarSize,
|
||||
child: RecipientAvatar(
|
||||
isVisible: true,
|
||||
name: recipient.name,
|
||||
avatarUrl: recipient.avatarUrl,
|
||||
avatarRadius: _avatarRadius,
|
||||
nameStyle: _nameStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/search.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/long_list/long_list.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/short_list.dart';
|
||||
import 'package:pweb/providers/recipient.dart';
|
||||
|
||||
|
||||
class AdressBookPayout extends StatefulWidget {
|
||||
final ValueChanged<Recipient> onSelected;
|
||||
|
||||
const AdressBookPayout({
|
||||
super.key,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AdressBookPayout> createState() => _AdressBookPayoutState();
|
||||
}
|
||||
|
||||
class _AdressBookPayoutState extends State<AdressBookPayout> {
|
||||
static const double _expandedHeight = 400;
|
||||
static const double _collapsedHeight = 200;
|
||||
static const double _cardMargin = 1;
|
||||
static const double _paddingAll = 16;
|
||||
static const double _spacingBetween = 16;
|
||||
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
late final TextEditingController _searchController;
|
||||
|
||||
bool get _isExpanded => _searchFocusNode.hasFocus;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final provider = context.read<RecipientProvider>();
|
||||
_searchController = TextEditingController(text: provider.query);
|
||||
|
||||
_searchController.addListener(() {
|
||||
provider.setQuery(_searchController.text);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<RecipientProvider>();
|
||||
|
||||
if (provider.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (provider.error != null) {
|
||||
return Center(child: Text('Error: ${provider.error}'));
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: _isExpanded ? _expandedHeight : _collapsedHeight,
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(_cardMargin),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
elevation: 4,
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_paddingAll),
|
||||
child: Column(
|
||||
children: [
|
||||
RecipientSearchField(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocusNode,
|
||||
onChanged: (_) {},
|
||||
),
|
||||
const SizedBox(height: _spacingBetween),
|
||||
Expanded(
|
||||
child: _isExpanded
|
||||
? LongListAdressBookPayout(
|
||||
filteredRecipients: provider.filteredRecipients,
|
||||
onSelected: widget.onSelected,
|
||||
)
|
||||
: ShortListAdressBookPayout(
|
||||
recipients: provider.recipients,
|
||||
onSelected: widget.onSelected,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/form.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentDetailsSection extends StatelessWidget {
|
||||
final bool isFormVisible;
|
||||
final bool isEditable;
|
||||
final VoidCallback? onToggle;
|
||||
final PaymentType? selectedType;
|
||||
final Object? data;
|
||||
|
||||
const PaymentDetailsSection({
|
||||
super.key,
|
||||
required this.isFormVisible,
|
||||
this.onToggle,
|
||||
required this.selectedType,
|
||||
required this.data,
|
||||
required this.isEditable,
|
||||
});
|
||||
|
||||
static const double toggleSpacing = 8.0;
|
||||
static const double formVisibleSpacing = 30.0;
|
||||
static const double formHiddenSpacing = 20.0;
|
||||
static const Duration animationDuration = Duration(milliseconds: 200);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
final toggleIcon = isFormVisible ? Icons.expand_less : Icons.expand_more;
|
||||
final toggleText = isFormVisible ? loc.hideDetails : loc.showDetails;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
if (!isEditable && onToggle != null)
|
||||
TextButton.icon(
|
||||
onPressed: onToggle,
|
||||
icon: Icon(toggleIcon, color: theme.colorScheme.primary),
|
||||
label: Text(
|
||||
toggleText,
|
||||
style: TextStyle(color: theme.colorScheme.primary),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: toggleSpacing),
|
||||
AnimatedCrossFade(
|
||||
duration: animationDuration,
|
||||
crossFadeState: isFormVisible
|
||||
? CrossFadeState.showFirst
|
||||
: CrossFadeState.showSecond,
|
||||
firstChild: PaymentMethodForm(
|
||||
key: const ValueKey('formVisible'),
|
||||
isEditable: isEditable,
|
||||
selectedType: selectedType,
|
||||
onChanged: (_) {},
|
||||
initialData: data,
|
||||
),
|
||||
secondChild: const SizedBox.shrink(key: ValueKey('formHidden')),
|
||||
),
|
||||
SizedBox(height: isFormVisible ? formVisibleSpacing : formHiddenSpacing),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
|
||||
|
||||
|
||||
class RecipientHeader extends StatelessWidget{
|
||||
final Recipient recipient;
|
||||
|
||||
const RecipientHeader({super.key, required this.recipient});
|
||||
|
||||
final double _avatarRadius = 20;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: RecipientAvatar(
|
||||
isVisible: false,
|
||||
name: recipient.name,
|
||||
avatarUrl: recipient.avatarUrl,
|
||||
avatarRadius: _avatarRadius,
|
||||
nameStyle: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
title: Text(recipient.name, style: theme.textTheme.titleLarge),
|
||||
subtitle: Text(recipient.email, style: theme.textTheme.bodyLarge),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/single/new_recipient/type.dart';
|
||||
|
||||
|
||||
class SinglePayout extends StatelessWidget {
|
||||
final void Function(PaymentType type) onGoToPayment;
|
||||
|
||||
static const double _cardPadding = 30.0;
|
||||
static const double _dividerPaddingVertical = 12.0;
|
||||
static const double _cardBorderRadius = 12.0;
|
||||
static const double _dividerThickness = 1.0;
|
||||
|
||||
const SinglePayout({super.key, required this.onGoToPayment});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final paymentTypes = PaymentType.values;
|
||||
final dividerColor = Theme.of(context).dividerColor;
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(_cardBorderRadius),
|
||||
),
|
||||
elevation: 4,
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_cardPadding),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < paymentTypes.length; i++) ...[
|
||||
PaymentTypeTile(
|
||||
type: paymentTypes[i],
|
||||
onSelected: onGoToPayment,
|
||||
),
|
||||
if (i < paymentTypes.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: _dividerPaddingVertical),
|
||||
child: Divider(thickness: _dividerThickness, color: dividerColor),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/icon.dart';
|
||||
import 'package:pweb/utils/payment/label.dart';
|
||||
|
||||
|
||||
class PaymentTypeTile extends StatelessWidget {
|
||||
final PaymentType type;
|
||||
final void Function(PaymentType type) onSelected;
|
||||
|
||||
const PaymentTypeTile({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = getPaymentTypeLabel(context, type);
|
||||
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: () => onSelected(type),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(iconForPaymentType(type), size: 24),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
35
frontend/pweb/lib/pages/dashboard/payouts/single/widget.dart
Normal file
35
frontend/pweb/lib/pages/dashboard/payouts/single/widget.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/widget.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/new_recipient/payout.dart';
|
||||
|
||||
|
||||
class SinglePayoutForm extends StatelessWidget {
|
||||
final ValueChanged<Recipient> onRecipientSelected;
|
||||
final void Function(PaymentType type) onGoToPayment;
|
||||
|
||||
const SinglePayoutForm({
|
||||
super.key,
|
||||
required this.onRecipientSelected,
|
||||
required this.onGoToPayment,
|
||||
});
|
||||
|
||||
static const double _spacingBetweenAddressAndForm = 20.0;
|
||||
static const double _bottomSpacing = 40.0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AdressBookPayout(onSelected: onRecipientSelected),
|
||||
const SizedBox(height: _spacingBetweenAddressAndForm),
|
||||
SinglePayout(onGoToPayment: onGoToPayment),
|
||||
const SizedBox(height: _bottomSpacing),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user