import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import '../providers/db_provider.dart'; import '../theme/app_theme.dart'; class TransactionsScreen extends ConsumerWidget { const TransactionsScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final all = ref.watch(allTransactionsProvider).valueOrNull ?? []; final query = ref.watch(searchQueryProvider).toLowerCase(); final filtered = query.isEmpty ? all : all.where((t) => t.payee.toLowerCase().contains(query)).toList(); return ListView.builder( padding: const EdgeInsets.fromLTRB(16, 8, 16, 90), itemCount: filtered.length, itemBuilder: (context, index) { final t = filtered[index]; return Card( margin: const EdgeInsets.only(bottom: 4), child: ListTile( dense: true, leading: CircleAvatar( radius: 18, backgroundColor: Theme.of(context).colorScheme.primaryContainer, child: Icon( t.amount >= 0 ? Icons.arrow_downward : Icons.arrow_upward, size: 16, color: t.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error, ), ), title: Text(t.payee, style: Theme.of(context).textTheme.bodyMedium), subtitle: Text( DateFormat('dd/MM/yy').format(t.date), style: Theme.of(context).textTheme.bodySmall, ), trailing: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( formatCurrency(t.amount), style: Theme.of(context).textTheme.bodyMedium?.copyWith( fontWeight: FontWeight.w600, color: t.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error, ), ), ], ), ), ); }, ); } }