Frontend first draft
This commit is contained in:
61
frontend/pweb/lib/pages/address_book/page/filter_button.dart
Normal file
61
frontend/pweb/lib/pages/address_book/page/filter_button.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/filter.dart';
|
||||
|
||||
|
||||
class RecipientFilterButton extends StatelessWidget {
|
||||
final String text;
|
||||
final RecipientFilter filter;
|
||||
final RecipientFilter selected;
|
||||
final ValueChanged<RecipientFilter> onTap;
|
||||
|
||||
const RecipientFilterButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.filter,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isSelected = selected == filter;
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
|
||||
return ElevatedButton(
|
||||
onPressed: () => onTap(filter),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(Colors.transparent),
|
||||
overlayColor: WidgetStateProperty.all(Colors.transparent),
|
||||
shadowColor: WidgetStateProperty.all(Colors.transparent),
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
),
|
||||
child: IntrinsicWidth(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: isSelected
|
||||
? theme.onPrimaryContainer
|
||||
: theme.onPrimaryContainer.withAlpha(60),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 2,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? theme.primary
|
||||
: theme.onPrimaryContainer.withAlpha(60),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
44
frontend/pweb/lib/pages/address_book/page/header.dart
Normal file
44
frontend/pweb/lib/pages/address_book/page/header.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class RecipientAddressBookHeader extends StatelessWidget {
|
||||
final VoidCallback onAddRecipient;
|
||||
|
||||
const RecipientAddressBookHeader({super.key, required this.onAddRecipient});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context).colorScheme;
|
||||
final l10 = AppLocalizations.of(context)!;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
l10.recipients,
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: onAddRecipient,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(theme.primary),
|
||||
shadowColor: WidgetStateProperty.all(theme.onPrimaryContainer),
|
||||
elevation: WidgetStateProperty.all(2),
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
),
|
||||
icon: Icon(Icons.add, color: theme.onSecondary),
|
||||
label: Text(l10.addRecipient, style: TextStyle(color: theme.onSecondary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
40
frontend/pweb/lib/pages/address_book/page/list.dart
Normal file
40
frontend/pweb/lib/pages/address_book/page/list.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/recipient/item.dart';
|
||||
|
||||
|
||||
class RecipientAddressBookList extends StatelessWidget {
|
||||
final List<Recipient> filteredRecipients;
|
||||
final ValueChanged<Recipient>? onSelected;
|
||||
final ValueChanged<Recipient>? onEdit;
|
||||
final ValueChanged<Recipient>? onDelete;
|
||||
|
||||
const RecipientAddressBookList({
|
||||
super.key,
|
||||
required this.filteredRecipients,
|
||||
this.onSelected,
|
||||
this.onEdit,
|
||||
this.onDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: filteredRecipients.length,
|
||||
itemBuilder: (context, index) {
|
||||
final recipient = filteredRecipients[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: RecipientAddressBookItem(
|
||||
recipient: recipient,
|
||||
onTap: () => onSelected?.call(recipient),
|
||||
onEdit: () => onEdit?.call(recipient),
|
||||
onDelete: () => onDelete?.call(recipient),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
102
frontend/pweb/lib/pages/address_book/page/page.dart
Normal file
102
frontend/pweb/lib/pages/address_book/page/page.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/filter.dart';
|
||||
import 'package:pweb/pages/address_book/page/filter_button.dart';
|
||||
import 'package:pweb/pages/address_book/page/header.dart';
|
||||
import 'package:pweb/pages/address_book/page/list.dart';
|
||||
import 'package:pweb/pages/address_book/page/search.dart';
|
||||
import 'package:pweb/providers/recipient.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class RecipientAddressBookPage extends StatelessWidget {
|
||||
final ValueChanged<Recipient> onRecipientSelected;
|
||||
final VoidCallback onAddRecipient;
|
||||
final ValueChanged<Recipient>? onEditRecipient;
|
||||
|
||||
const RecipientAddressBookPage({
|
||||
super.key,
|
||||
required this.onRecipientSelected,
|
||||
required this.onAddRecipient,
|
||||
this.onEditRecipient,
|
||||
});
|
||||
|
||||
static const double _expandedHeight = 550;
|
||||
static const double _paddingAll = 16;
|
||||
static const double _bigBox = 30;
|
||||
static const double _smallBox = 20;
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<RecipientProvider>();
|
||||
|
||||
if (provider.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator()); //TODO This should be in the provider
|
||||
}
|
||||
|
||||
if (provider.error != null) {
|
||||
return Center(child: Text('Error: ${provider.error}'));
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
RecipientAddressBookHeader(onAddRecipient: onAddRecipient),
|
||||
const SizedBox(height: _smallBox),
|
||||
RecipientSearchField(
|
||||
controller: TextEditingController(text: provider.query),
|
||||
focusNode: FocusNode(),
|
||||
onChanged: provider.setQuery,
|
||||
),
|
||||
const SizedBox(height: _bigBox),
|
||||
Row(
|
||||
children: [
|
||||
RecipientFilterButton(
|
||||
text: loc.allStatus,
|
||||
filter: RecipientFilter.all,
|
||||
selected: provider.selectedFilter,
|
||||
onTap: provider.setFilter,
|
||||
),
|
||||
RecipientFilterButton(
|
||||
text: loc.readyStatus,
|
||||
filter: RecipientFilter.ready,
|
||||
selected: provider.selectedFilter,
|
||||
onTap: provider.setFilter,
|
||||
),
|
||||
RecipientFilterButton(
|
||||
text: loc.registeredStatus,
|
||||
filter: RecipientFilter.registered,
|
||||
selected: provider.selectedFilter,
|
||||
onTap: provider.setFilter,
|
||||
),
|
||||
RecipientFilterButton(
|
||||
text: loc.notRegisteredStatus,
|
||||
filter: RecipientFilter.notRegistered,
|
||||
selected: provider.selectedFilter,
|
||||
onTap: provider.setFilter,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: _expandedHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_paddingAll),
|
||||
child: RecipientAddressBookList(
|
||||
filteredRecipients: provider.filteredRecipients,
|
||||
onEdit: (recipient) => onEditRecipient?.call(recipient),
|
||||
onSelected: onRecipientSelected,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class RecipientActions extends StatelessWidget {
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
const RecipientActions({super.key, required this.onEdit, required this.onDelete});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(icon: Icon(Icons.edit, color: Theme.of(context).colorScheme.primary), onPressed: onEdit),
|
||||
IconButton(icon: Icon(Icons.delete, color: Theme.of(context).colorScheme.error), onPressed: onDelete),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class RecipientInfoColumn extends StatelessWidget {
|
||||
final String name;
|
||||
final String email;
|
||||
|
||||
const RecipientInfoColumn({super.key, required this.name, required this.email});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(name, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontSize: 19)),
|
||||
Text(email, style: Theme.of(context).textTheme.bodyMedium),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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 RecipientAddressBookInfoRow extends StatelessWidget {
|
||||
final PaymentType type;
|
||||
final String value;
|
||||
|
||||
final double spacingWidth;
|
||||
final double spacingHeight;
|
||||
final double iconSize;
|
||||
final double titleFontSize;
|
||||
final double valueFontSize;
|
||||
final TextStyle? textStyle;
|
||||
|
||||
const RecipientAddressBookInfoRow({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.value,
|
||||
this.spacingWidth = 8.0,
|
||||
this.spacingHeight = 2.0,
|
||||
this.iconSize = 20.0,
|
||||
this.titleFontSize = 16.0,
|
||||
this.valueFontSize = 12.0,
|
||||
this.textStyle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = textStyle ?? Theme.of(context).textTheme.bodySmall!;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(iconForPaymentType(type), size: iconSize),
|
||||
SizedBox(width: spacingWidth),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
getPaymentTypeLabel(context, type),
|
||||
style: style.copyWith(fontSize: titleFontSize),
|
||||
),
|
||||
SizedBox(height: spacingHeight),
|
||||
Text(
|
||||
value,
|
||||
style: style.copyWith(fontSize: valueFontSize),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/recipient/actions.dart';
|
||||
import 'package:pweb/pages/address_book/page/recipient/info_column.dart';
|
||||
import 'package:pweb/pages/address_book/page/recipient/payment_row.dart';
|
||||
import 'package:pweb/pages/address_book/page/recipient/status.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
|
||||
|
||||
|
||||
class RecipientAddressBookItem extends StatefulWidget {
|
||||
final Recipient recipient;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
final double borderRadius;
|
||||
final double elevation;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double spacingDotAvatar;
|
||||
final double spacingAvatarInfo;
|
||||
final double spacingBottom;
|
||||
final double avatarRadius;
|
||||
|
||||
const RecipientAddressBookItem({
|
||||
super.key,
|
||||
required this.recipient,
|
||||
required this.onTap,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
this.borderRadius = 12,
|
||||
this.elevation = 4,
|
||||
this.padding = const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
this.spacingDotAvatar = 8,
|
||||
this.spacingAvatarInfo = 16,
|
||||
this.spacingBottom = 10,
|
||||
this.avatarRadius = 24,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RecipientAddressBookItem> createState() => _RecipientAddressBookItemState();
|
||||
}
|
||||
|
||||
class _RecipientAddressBookItemState extends State<RecipientAddressBookItem> {
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final recipient = widget.recipient;
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHovered = true),
|
||||
onExit: (_) => setState(() => _isHovered = false),
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius)),
|
||||
elevation: widget.elevation,
|
||||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
RecipientStatusDot(status: recipient.status),
|
||||
SizedBox(width: widget.spacingDotAvatar),
|
||||
RecipientAvatar(
|
||||
name: recipient.name,
|
||||
avatarUrl: recipient.avatarUrl,
|
||||
isVisible: false,
|
||||
avatarRadius: widget.avatarRadius,
|
||||
),
|
||||
SizedBox(width: widget.spacingAvatarInfo),
|
||||
Expanded(
|
||||
child: RecipientInfoColumn(
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
),
|
||||
),
|
||||
if (_isHovered)
|
||||
RecipientActions(
|
||||
onEdit: widget.onEdit, onDelete: widget.onDelete),
|
||||
],
|
||||
),
|
||||
SizedBox(height: widget.spacingBottom),
|
||||
RecipientPaymentRow(recipient: recipient),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/recipient/info_row.dart';
|
||||
|
||||
|
||||
class RecipientPaymentRow extends StatelessWidget {
|
||||
final Recipient recipient;
|
||||
final double spacing;
|
||||
|
||||
const RecipientPaymentRow({
|
||||
super.key,
|
||||
required this.recipient,
|
||||
this.spacing = 18
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
spacing: spacing,
|
||||
children: [
|
||||
if (recipient.bank?.accountNumber.isNotEmpty ?? false)
|
||||
RecipientAddressBookInfoRow(
|
||||
type: PaymentType.bankAccount,
|
||||
value: recipient.bank!.accountNumber
|
||||
),
|
||||
if (recipient.card?.pan.isNotEmpty ?? false)
|
||||
RecipientAddressBookInfoRow(
|
||||
type: PaymentType.card,
|
||||
value: recipient.card!.pan
|
||||
),
|
||||
if (recipient.iban?.iban.isNotEmpty ?? false)
|
||||
RecipientAddressBookInfoRow(
|
||||
type: PaymentType.iban,
|
||||
value: recipient.iban!.iban
|
||||
),
|
||||
if (recipient.wallet?.walletId.isNotEmpty ?? false)
|
||||
RecipientAddressBookInfoRow(
|
||||
type: PaymentType.wallet,
|
||||
value: recipient.wallet!.walletId
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/status.dart';
|
||||
|
||||
|
||||
class RecipientStatusDot extends StatelessWidget {
|
||||
final RecipientStatus status;
|
||||
|
||||
const RecipientStatusDot({super.key, required this.status});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case RecipientStatus.ready:
|
||||
color = Colors.green;
|
||||
break;
|
||||
case RecipientStatus.notRegistered:
|
||||
color = Theme.of(context).colorScheme.error;
|
||||
break;
|
||||
case RecipientStatus.registered:
|
||||
color = Colors.yellow;
|
||||
break;
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(shape: BoxShape.circle, color: color),
|
||||
);
|
||||
}
|
||||
}
|
||||
44
frontend/pweb/lib/pages/address_book/page/search.dart
Normal file
44
frontend/pweb/lib/pages/address_book/page/search.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class RecipientSearchField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final ValueChanged<String> onChanged;
|
||||
final FocusNode? focusNode;
|
||||
|
||||
const RecipientSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onChanged,
|
||||
this.focusNode,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return TextField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
hintText: l10n.searchHint,
|
||||
border: const OutlineInputBorder(),
|
||||
fillColor: Theme.of(context).colorScheme.onSecondary,
|
||||
filled: true,
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
onChanged('');
|
||||
focusNode?.unfocus();
|
||||
},
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user