completed group batch feature
This commit is contained in:
@@ -8,54 +8,37 @@ class HistoryModel {
|
||||
|
||||
List<Map<String, dynamic>> transactions = [];
|
||||
bool isLoading = false;
|
||||
bool isLoadingMore = false;
|
||||
bool isActing = false;
|
||||
String? errorMessage;
|
||||
|
||||
int currentPage = 0;
|
||||
int totalPages = 0;
|
||||
|
||||
String searchQuery = '';
|
||||
String? statusFilter;
|
||||
String? typeFilter;
|
||||
|
||||
bool selectMode = false;
|
||||
Set<String> selectedTransactionIds = {};
|
||||
}
|
||||
|
||||
class HistoryController extends ChangeNotifier {
|
||||
final HistoryModel model = HistoryModel();
|
||||
final Http http = Http();
|
||||
BuildContext context;
|
||||
bool _disposed = false;
|
||||
|
||||
HistoryController(this.context);
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getTransactions(Map<String, String> params) async {
|
||||
model.isLoading = true;
|
||||
if (params['page'] == '0') {
|
||||
model.transactions = getFakeTransactions();
|
||||
}
|
||||
notifyListeners();
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, dynamic> response = await http.get(
|
||||
'/public/transaction?${buildQueryParameters(params)}',
|
||||
);
|
||||
|
||||
if (params['page'] == '0') {
|
||||
model.transactions = [];
|
||||
}
|
||||
|
||||
model.pageableModel = PageableModel.fromJson(response);
|
||||
|
||||
// pagination adds to current list instead of replacing it
|
||||
model.transactions =
|
||||
model.transactions +
|
||||
model.pageableModel!.content
|
||||
.map((e) => e as Map<String, dynamic>)
|
||||
.toList();
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.success(List<Map<String, dynamic>>.from(model.transactions));
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
model.transactions = [];
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem fetching transactions, are you connected to the internet?",
|
||||
);
|
||||
}
|
||||
void _safeNotify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
String buildQueryParameters(Map<String, String> params) {
|
||||
@@ -70,6 +53,152 @@ class HistoryController extends ChangeNotifier {
|
||||
return query.substring(0, query.length - 1);
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getTransactions(
|
||||
Map<String, String> params,
|
||||
) async {
|
||||
final isFirstPage = params['page'] == '0' || params['page'] == null;
|
||||
if (isFirstPage) {
|
||||
model.isLoading = true;
|
||||
model.transactions = [];
|
||||
model.currentPage = 0;
|
||||
} else {
|
||||
model.isLoadingMore = true;
|
||||
}
|
||||
_safeNotify();
|
||||
|
||||
params['partyType'] = 'INDIVIDUAL';
|
||||
|
||||
try {
|
||||
Map<String, dynamic> response = await http.get(
|
||||
'/public/transaction?${buildQueryParameters(params)}',
|
||||
);
|
||||
|
||||
model.pageableModel = PageableModel.fromJson(response);
|
||||
model.currentPage = model.pageableModel!.number;
|
||||
model.totalPages = model.pageableModel!.totalPages;
|
||||
|
||||
final newItems = model.pageableModel!.content
|
||||
.map((e) => Map<String, dynamic>.from(e as Map))
|
||||
.toList();
|
||||
|
||||
if (isFirstPage) {
|
||||
model.transactions = newItems;
|
||||
} else {
|
||||
model.transactions.addAll(newItems);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
model.isLoadingMore = false;
|
||||
_safeNotify();
|
||||
return ApiResponse.success(model.transactions);
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
if (isFirstPage) {
|
||||
model.transactions = [];
|
||||
}
|
||||
model.isLoading = false;
|
||||
model.isLoadingMore = false;
|
||||
_safeNotify();
|
||||
return ApiResponse.failure(
|
||||
"Problem fetching transactions, are you connected to the internet?",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchTransactions(
|
||||
String userId, {
|
||||
String? search,
|
||||
String? status,
|
||||
String? type,
|
||||
}) async {
|
||||
model.searchQuery = search ?? '';
|
||||
model.statusFilter = status;
|
||||
model.typeFilter = type;
|
||||
final params = <String, String>{
|
||||
'userId': userId,
|
||||
'page': '0',
|
||||
'size': '20',
|
||||
'sort': 'createdAt,desc',
|
||||
};
|
||||
if (search != null && search.isNotEmpty) {
|
||||
params['creditAccount'] = search;
|
||||
params['creditEmail'] = search;
|
||||
params['creditPhone'] = search;
|
||||
params['creditName'] = search;
|
||||
params['billName'] = search;
|
||||
params['amount'] = search;
|
||||
}
|
||||
if (status != null && status.isNotEmpty) {
|
||||
params['status'] = status;
|
||||
}
|
||||
if (type != null && type.isNotEmpty) {
|
||||
params['type'] = type;
|
||||
}
|
||||
await getTransactions(params);
|
||||
}
|
||||
|
||||
Future<void> loadNextPage(String userId) async {
|
||||
if (model.isLoadingMore || model.currentPage + 1 >= model.totalPages) {
|
||||
return;
|
||||
}
|
||||
final params = <String, String>{
|
||||
'userId': userId,
|
||||
'page': (model.currentPage + 1).toString(),
|
||||
'size': '20',
|
||||
'sort': 'createdAt,desc',
|
||||
};
|
||||
if (model.searchQuery.isNotEmpty) {
|
||||
params['creditAccount'] = model.searchQuery;
|
||||
params['creditEmail'] = model.searchQuery;
|
||||
params['creditPhone'] = model.searchQuery;
|
||||
params['creditName'] = model.searchQuery;
|
||||
params['billName'] = model.searchQuery;
|
||||
params['amount'] = model.searchQuery;
|
||||
}
|
||||
if (model.statusFilter != null && model.statusFilter!.isNotEmpty) {
|
||||
params['status'] = model.statusFilter!;
|
||||
}
|
||||
if (model.typeFilter != null && model.typeFilter!.isNotEmpty) {
|
||||
params['type'] = model.typeFilter!;
|
||||
}
|
||||
await getTransactions(params);
|
||||
}
|
||||
|
||||
void toggleSelectMode() {
|
||||
model.selectMode = !model.selectMode;
|
||||
if (!model.selectMode) {
|
||||
model.selectedTransactionIds.clear();
|
||||
}
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
void toggleTransactionSelection(String id) {
|
||||
if (id.isEmpty) return;
|
||||
if (model.selectedTransactionIds.contains(id)) {
|
||||
model.selectedTransactionIds.remove(id);
|
||||
} else {
|
||||
model.selectedTransactionIds.add(id);
|
||||
}
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
/// Removes selected transactions from the local list. The history
|
||||
/// endpoint does not support deletes, so this is a client-side action.
|
||||
void deleteSelectedTransactions() {
|
||||
final ids = List<String>.from(model.selectedTransactionIds);
|
||||
model.transactions.removeWhere((t) => ids.contains(t['id'] as String?));
|
||||
model.selectMode = false;
|
||||
model.selectedTransactionIds.clear();
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
void clearFilters() {
|
||||
model.statusFilter = null;
|
||||
model.typeFilter = null;
|
||||
_safeNotify();
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> getFakeTransactions() {
|
||||
return [
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:qpay/screens/receipt/receipt_controller.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:qpay/screens/history/history_controller.dart';
|
||||
import 'package:qpay/widgets/app_snack_bar.dart';
|
||||
import 'package:qpay/widgets/transaction_item_widget.dart';
|
||||
import 'package:qpay/screens/transactions/transaction_model.dart' as txn;
|
||||
|
||||
@@ -20,39 +21,61 @@ class _HistoryScreenState extends State<HistoryScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late HistoryController controller;
|
||||
late SharedPreferences prefs;
|
||||
late AnimationController _controller;
|
||||
late TransactionController transactionController;
|
||||
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final Map<String, String> _queryParams = {};
|
||||
final int _pageSize = 8;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
late final AnimationController _entryController;
|
||||
late final Animation<double> _entryFade;
|
||||
late final Animation<Offset> _entrySlide;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = HistoryController(context);
|
||||
setupData();
|
||||
|
||||
transactionController = Provider.of<TransactionController>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 3000),
|
||||
// Short, subtle entry animation (replaces the old 3-second stagger)
|
||||
_entryController = AnimationController(
|
||||
duration: const Duration(milliseconds: 220),
|
||||
vsync: this,
|
||||
)..forward();
|
||||
);
|
||||
_entryFade = Tween<double>(
|
||||
begin: 0.0,
|
||||
end: 1.0,
|
||||
).animate(CurvedAnimation(parent: _entryController, curve: Curves.easeOut));
|
||||
_entrySlide = Tween<Offset>(
|
||||
begin: const Offset(0, 0.02),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(parent: _entryController, curve: Curves.easeOut));
|
||||
_entryController.forward();
|
||||
|
||||
// Listen to controller changes to rebuild when transactions are loaded
|
||||
controller.addListener(() => setState(() {}));
|
||||
_searchController.addListener(() => setState(() {}));
|
||||
_scrollController.addListener(_onScroll);
|
||||
|
||||
setupData();
|
||||
}
|
||||
|
||||
void setupData() async {
|
||||
Future<void> setupData() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
await controller.searchTransactions(userId);
|
||||
}
|
||||
|
||||
await controller.getTransactions({
|
||||
'userId': prefs.getString("userId")!,
|
||||
'page': '0',
|
||||
'size': _pageSize.toString(),
|
||||
'sort': 'createdAt,desc',
|
||||
});
|
||||
void _onScroll() {
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 200) {
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
if (userId.isNotEmpty) {
|
||||
controller.loadNextPage(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the repeat action for a transaction.
|
||||
@@ -60,10 +83,178 @@ class _HistoryScreenState extends State<HistoryScreen>
|
||||
final receiptController = ReceiptController(context);
|
||||
final transaction = txn.TransactionModel.fromJson(item);
|
||||
await receiptController.repeatTransaction(transaction);
|
||||
if (mounted) {
|
||||
context.push('/make-payment');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDeleteSelected() async {
|
||||
final count = controller.model.selectedTransactionIds.length;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Delete transactions'),
|
||||
content: Text('Remove $count transaction(s) from this list?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
controller.deleteSelectedTransactions();
|
||||
if (mounted) {
|
||||
AppSnackBar.show(
|
||||
context,
|
||||
'Transactions removed from this list',
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showFilterSheet() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setSheetState) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Filter Transactions',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setSheetState(() {
|
||||
controller.model.statusFilter = null;
|
||||
controller.model.typeFilter = null;
|
||||
});
|
||||
},
|
||||
child: const Text('Clear All'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String?>(
|
||||
initialValue: controller.model.statusFilter,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Status',
|
||||
filled: true,
|
||||
fillColor: Colors.grey.shade100,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('All')),
|
||||
DropdownMenuItem(
|
||||
value: 'SUCCESS',
|
||||
child: Text('Success'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'PENDING',
|
||||
child: Text('Pending'),
|
||||
),
|
||||
DropdownMenuItem(value: 'FAILED', child: Text('Failed')),
|
||||
],
|
||||
onChanged: (v) {
|
||||
setSheetState(() => controller.model.statusFilter = v);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String?>(
|
||||
initialValue: controller.model.typeFilter,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Type',
|
||||
filled: true,
|
||||
fillColor: Colors.grey.shade100,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('All')),
|
||||
DropdownMenuItem(
|
||||
value: 'REQUEST',
|
||||
child: Text('Request'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'PAYMENT',
|
||||
child: Text('Payment'),
|
||||
),
|
||||
DropdownMenuItem(value: 'REFUND', child: Text('Refund')),
|
||||
],
|
||||
onChanged: (v) {
|
||||
setSheetState(() => controller.model.typeFilter = v);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
controller.searchTransactions(
|
||||
userId,
|
||||
search: _searchController.text.isNotEmpty
|
||||
? _searchController.text
|
||||
: null,
|
||||
status: controller.model.statusFilter,
|
||||
type: controller.model.typeFilter,
|
||||
);
|
||||
},
|
||||
child: const Text('Apply Filters'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_scrollController.dispose();
|
||||
_entryController.dispose();
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -71,96 +262,309 @@ class _HistoryScreenState extends State<HistoryScreen>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
title: Text(
|
||||
'History',
|
||||
style: TextStyle(fontSize: 20, color: Colors.black),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: ListenableBuilder(
|
||||
listenable: controller,
|
||||
builder: (context, child) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return SizedBox(
|
||||
width: double.parse(
|
||||
constraints.maxWidth > ResponsivePolicy.md
|
||||
? ResponsivePolicy.md.toString()
|
||||
: constraints.maxWidth.toString(),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSearchField(controller),
|
||||
SizedBox(height: 10),
|
||||
if (controller.model.transactions.isEmpty)
|
||||
Column(
|
||||
appBar: AppBar(title: const Text('History'), centerTitle: true),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: CustomScrollView(
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: FadeTransition(
|
||||
opacity: _entryFade,
|
||||
child: SlideTransition(
|
||||
position: _entrySlide,
|
||||
child: Center(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width =
|
||||
constraints.maxWidth > ResponsivePolicy.md
|
||||
? ResponsivePolicy.md.toDouble()
|
||||
: constraints.maxWidth;
|
||||
return SizedBox(
|
||||
width: width,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 30),
|
||||
Text(
|
||||
'No transactions yet. Make a payment to see your recent activity.',
|
||||
style: TextStyle(fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
_buildSearchRow(),
|
||||
const SizedBox(height: 12),
|
||||
_buildContent(),
|
||||
],
|
||||
),
|
||||
if (controller.model.transactions.isNotEmpty)
|
||||
Column(
|
||||
children: [
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
...controller.model.transactions.map(
|
||||
(e) =>
|
||||
_buildTransactionItem(e, context),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (controller.model.pageableModel !=
|
||||
null &&
|
||||
controller.model.pageableModel!.number <
|
||||
controller
|
||||
.model
|
||||
.pageableModel!
|
||||
.totalPages)
|
||||
OutlinedButton(
|
||||
child: Text('Load more'),
|
||||
onPressed: () {
|
||||
controller.getTransactions({
|
||||
'userId': prefs.getString(
|
||||
"userId",
|
||||
)!,
|
||||
'page':
|
||||
(controller
|
||||
.model
|
||||
.pageableModel!
|
||||
.number +
|
||||
1)
|
||||
.toString(),
|
||||
'size': _pageSize.toString(),
|
||||
'sort': 'createdAt,desc',
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (controller.model.selectMode) _buildSelectionBottomBar(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchRow() {
|
||||
final hasFilters =
|
||||
controller.model.statusFilter != null ||
|
||||
controller.model.typeFilter != null;
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search by name, account, email, phone',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
controller.searchTransactions(
|
||||
userId,
|
||||
status: controller.model.statusFilter,
|
||||
type: controller.model.typeFilter,
|
||||
);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
filled: true,
|
||||
fillColor: Colors.grey.shade100,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
textInputAction: TextInputAction.search,
|
||||
onFieldSubmitted: (value) {
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
controller.searchTransactions(
|
||||
userId,
|
||||
search: value.isNotEmpty ? value : null,
|
||||
status: controller.model.statusFilter,
|
||||
type: controller.model.typeFilter,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: Icons.filter_list,
|
||||
tooltip: 'Filter transactions',
|
||||
isActive: hasFilters,
|
||||
onPressed: _showFilterSheet,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: controller.model.selectMode
|
||||
? Icons.checklist
|
||||
: Icons.checklist_outlined,
|
||||
tooltip: 'Select transactions',
|
||||
isActive: controller.model.selectMode,
|
||||
onPressed: controller.toggleSelectMode,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: Icons.refresh,
|
||||
tooltip: 'Refresh transactions',
|
||||
isActive: false,
|
||||
onPressed: () async {
|
||||
await setupData();
|
||||
if (mounted) {
|
||||
AppSnackBar.show(
|
||||
context,
|
||||
'Transactions refreshed',
|
||||
duration: const Duration(seconds: 1),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildIconButton(
|
||||
icon: Icons.add,
|
||||
tooltip: 'New payment',
|
||||
isActive: false,
|
||||
onPressed: () => context.push('/recipients'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton({
|
||||
required IconData icon,
|
||||
required String tooltip,
|
||||
required bool isActive,
|
||||
required VoidCallback onPressed,
|
||||
}) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isActive
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icon, color: isActive ? Colors.white : Colors.grey.shade700),
|
||||
tooltip: tooltip,
|
||||
onPressed: onPressed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent() {
|
||||
if (controller.model.isLoading) {
|
||||
return const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 60),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (controller.model.transactions.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.receipt_long_outlined,
|
||||
size: 64,
|
||||
color: Colors.grey.shade400,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'No transactions yet.',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Tap + to make a new payment.',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final hasFilters =
|
||||
controller.model.statusFilter != null ||
|
||||
controller.model.typeFilter != null;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
if (controller.model.selectMode)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${controller.model.selectedTransactionIds.length} selected',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (hasFilters)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
if (controller.model.statusFilter != null)
|
||||
_activeFilterChip(
|
||||
'Status: ${controller.model.statusFilter}',
|
||||
() {
|
||||
controller.model.statusFilter = null;
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
controller.searchTransactions(
|
||||
userId,
|
||||
search: _searchController.text.isNotEmpty
|
||||
? _searchController.text
|
||||
: null,
|
||||
type: controller.model.typeFilter,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (controller.model.typeFilter != null)
|
||||
_activeFilterChip('Type: ${controller.model.typeFilter}', () {
|
||||
controller.model.typeFilter = null;
|
||||
final userId = prefs.getString("userId") ?? '';
|
||||
controller.searchTransactions(
|
||||
userId,
|
||||
search: _searchController.text.isNotEmpty
|
||||
? _searchController.text
|
||||
: null,
|
||||
status: controller.model.statusFilter,
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
...controller.model.transactions.map(
|
||||
(e) => _buildTransactionItem(e, context),
|
||||
),
|
||||
if (controller.model.isLoadingMore)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _activeFilterChip(String label, VoidCallback onRemove) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary.withAlpha(20),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.primary.withAlpha(60),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
InkWell(
|
||||
onTap: onRemove,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 14,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -168,102 +572,108 @@ class _HistoryScreenState extends State<HistoryScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchField(HistoryController controller) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
textInputAction: TextInputAction.search,
|
||||
onFieldSubmitted: (value) {
|
||||
_queryParams.clear();
|
||||
setState(() {
|
||||
_queryParams['creditAccount'] = _searchController.text;
|
||||
_queryParams['creditEmail'] = _searchController.text;
|
||||
_queryParams['creditPhone'] = _searchController.text;
|
||||
_queryParams['creditName'] = _searchController.text;
|
||||
_queryParams['billName'] = _searchController.text;
|
||||
_queryParams['amount'] = _searchController.text;
|
||||
_queryParams['userId'] = prefs.getString("userId")!;
|
||||
Widget _buildTransactionItem(Map<String, dynamic> e, BuildContext context) {
|
||||
final id = e['id'] as String? ?? '';
|
||||
final isSelected = controller.model.selectedTransactionIds.contains(id);
|
||||
final inSelectMode = controller.model.selectMode;
|
||||
|
||||
controller.getTransactions(_queryParams);
|
||||
});
|
||||
return Stack(
|
||||
children: [
|
||||
TransactionItemWidget(
|
||||
transaction: e,
|
||||
enabled: controller.model.isLoading,
|
||||
onRepeat: inSelectMode
|
||||
? null
|
||||
: () async {
|
||||
await _repeatTransaction(e);
|
||||
},
|
||||
controller: _searchController,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search by name, account, email, phone',
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
if (inSelectMode)
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: () => controller.toggleTransactionSelection(id),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withValues(alpha: 0.08)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withValues(alpha: 0.2),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
isSelected
|
||||
? Icons.check_box
|
||||
: Icons.check_box_outline_blank,
|
||||
size: 22,
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIcon: _searchController.text.isNotEmpty
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
_queryParams.clear();
|
||||
controller.getTransactions({
|
||||
'userId': prefs.getString("userId")!,
|
||||
});
|
||||
},
|
||||
icon: Icon(Icons.clear),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
onChanged: (value) {
|
||||
// controller.updateCreditAccount(value);
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter an amount';
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return 'Please enter a valid amount';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTransactionItem(Map<String, dynamic> e, BuildContext context) {
|
||||
int index = controller.model.transactions.indexOf(e);
|
||||
Animation<Offset> animation =
|
||||
Tween<Offset>(begin: Offset(0, -0.25), end: Offset.zero).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Interval(0.175 * index, 1.0, curve: Curves.easeIn),
|
||||
Widget _buildSelectionBottomBar() {
|
||||
final selectedCount = controller.model.selectedTransactionIds.length;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.08),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
);
|
||||
|
||||
return SlideTransition(
|
||||
position: animation,
|
||||
child: TransactionItemWidget(
|
||||
transaction: e,
|
||||
enabled: controller.model.isLoading,
|
||||
onRepeat: () async {
|
||||
await _repeatTransaction(e);
|
||||
if (context.mounted) {
|
||||
context.push('/make-payment');
|
||||
}
|
||||
},
|
||||
],
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'$selectedCount selected',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton.icon(
|
||||
onPressed: () => controller.toggleSelectMode(),
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
label: const Text('Cancel'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
TextButton.icon(
|
||||
onPressed: selectedCount > 0 ? _onDeleteSelected : null,
|
||||
icon: const Icon(Icons.delete_outline, size: 20),
|
||||
label: const Text('Delete'),
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user