Multiple Wallet support, history of each wallet and updated payment page
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/search.dart';
|
||||
import 'package:pweb/pages/payment_methods/widgets/section_title.dart';
|
||||
import 'package:pweb/providers/recipient.dart';
|
||||
import 'package:pweb/utils/dimensions.dart';
|
||||
|
||||
|
||||
class RecipientSection extends StatelessWidget {
|
||||
final Recipient? recipient;
|
||||
final AppDimensions dimensions;
|
||||
final RecipientProvider recipientProvider;
|
||||
final TextEditingController searchController;
|
||||
final FocusNode searchFocusNode;
|
||||
final ValueChanged<String> onSearchChanged;
|
||||
final ValueChanged<Recipient> onRecipientSelected;
|
||||
final VoidCallback onRecipientCleared;
|
||||
|
||||
const RecipientSection({
|
||||
super.key,
|
||||
required this.recipient,
|
||||
required this.dimensions,
|
||||
required this.recipientProvider,
|
||||
required this.searchController,
|
||||
required this.searchFocusNode,
|
||||
required this.onSearchChanged,
|
||||
required this.onRecipientSelected,
|
||||
required this.onRecipientCleared,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (recipient != null) {
|
||||
return SelectedRecipientCard(
|
||||
dimensions: dimensions,
|
||||
recipient: recipient!,
|
||||
onClear: onRecipientCleared,
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SectionTitle('Recipient'),
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
RecipientSearchField(
|
||||
controller: searchController,
|
||||
onChanged: onSearchChanged,
|
||||
focusNode: searchFocusNode,
|
||||
),
|
||||
if (recipientProvider.query.isNotEmpty) ...[
|
||||
SizedBox(height: dimensions.paddingMedium),
|
||||
RecipientSearchResults(
|
||||
dimensions: dimensions,
|
||||
recipientProvider: recipientProvider,
|
||||
onRecipientSelected: onRecipientSelected,
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SelectedRecipientCard extends StatelessWidget {
|
||||
final AppDimensions dimensions;
|
||||
final Recipient recipient;
|
||||
final VoidCallback onClear;
|
||||
|
||||
const SelectedRecipientCard({
|
||||
super.key,
|
||||
required this.dimensions,
|
||||
required this.recipient,
|
||||
required this.onClear,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(dimensions.paddingMedium),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceVariant.withOpacity(0.4),
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SectionTitle('Recipient'),
|
||||
SizedBox(height: dimensions.paddingSmall),
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
child: Text(recipient.name.substring(0, 1).toUpperCase()),
|
||||
),
|
||||
SizedBox(width: dimensions.paddingMedium),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(recipient.name, style: theme.textTheme.titleMedium),
|
||||
if (recipient.email.isNotEmpty)
|
||||
Text(
|
||||
recipient.email,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: onClear,
|
||||
child: const Text('Choose another recipient'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecipientSearchResults extends StatelessWidget {
|
||||
final AppDimensions dimensions;
|
||||
final RecipientProvider recipientProvider;
|
||||
final ValueChanged<Recipient> onRecipientSelected;
|
||||
|
||||
const RecipientSearchResults({
|
||||
super.key,
|
||||
required this.dimensions,
|
||||
required this.recipientProvider,
|
||||
required this.onRecipientSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (recipientProvider.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (recipientProvider.error != null) {
|
||||
return Text(
|
||||
recipientProvider.error!,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
);
|
||||
}
|
||||
|
||||
if (recipientProvider.recipients.isEmpty) {
|
||||
return const Text('No recipients yet.');
|
||||
}
|
||||
|
||||
final results = recipientProvider.filteredRecipients;
|
||||
|
||||
if (results.isEmpty) {
|
||||
return const Text('No recipients found for this query.');
|
||||
}
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 240),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemCount: results.length,
|
||||
separatorBuilder: (_, __) => SizedBox(height: dimensions.paddingSmall),
|
||||
itemBuilder: (context, index) {
|
||||
final recipient = results[index];
|
||||
return ListTile(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
|
||||
),
|
||||
tileColor: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.2),
|
||||
leading: CircleAvatar(
|
||||
child: Text(recipient.name.substring(0, 1).toUpperCase()),
|
||||
),
|
||||
title: Text(recipient.name),
|
||||
subtitle: Text(recipient.email),
|
||||
trailing: const Icon(Icons.arrow_forward_ios_rounded, size: 16),
|
||||
onTap: () => onRecipientSelected(recipient),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user