71 lines
2.2 KiB
Dart
71 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../providers/db_provider.dart';
|
|
import '../theme/app_theme.dart';
|
|
|
|
class AccountsScreen extends ConsumerWidget {
|
|
const AccountsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final all = ref.watch(openAccountsProvider);
|
|
final query = ref.watch(searchQueryProvider).toLowerCase();
|
|
final accounts = query.isEmpty
|
|
? all
|
|
: all.where((a) => a.name.toLowerCase().contains(query)).toList();
|
|
|
|
return ListView(
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 90),
|
|
children: [
|
|
...accounts.map((a) => _AccountCard(account: a)),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AccountCard extends StatelessWidget {
|
|
final Account account;
|
|
const _AccountCard({required this.account});
|
|
|
|
IconData _icon() {
|
|
switch (account.type) {
|
|
case 'savings': return Icons.savings_outlined;
|
|
case 'credit': return Icons.credit_card_outlined;
|
|
case 'cash': return Icons.money_outlined;
|
|
default: return Icons.account_balance_outlined;
|
|
}
|
|
}
|
|
|
|
String _label() {
|
|
switch (account.type) {
|
|
case 'checking': return 'Compte courant';
|
|
case 'savings': return 'Épargne';
|
|
case 'credit': return 'Carte de crédit';
|
|
case 'cash': return 'Espèces';
|
|
default: return account.type;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
child: ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
|
child: Icon(_icon(), color: Theme.of(context).colorScheme.onSurfaceVariant, size: 22),
|
|
),
|
|
title: Text(account.name, style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w600)),
|
|
subtitle: Text(_label(), style: Theme.of(context).textTheme.bodySmall),
|
|
trailing: Text(
|
|
formatCurrency(account.balance),
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|