90 lines
2.7 KiB
Dart
90 lines
2.7 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 accounts = ref.watch(openAccountsProvider);
|
|
|
|
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: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.primaryContainer,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Icon(_icon(), color: Theme.of(context).colorScheme.onSurfaceVariant, size: 22),
|
|
),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(account.name,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium
|
|
?.copyWith(fontWeight: FontWeight.w600)),
|
|
const SizedBox(height: 2),
|
|
Text(_label(), style: Theme.of(context).textTheme.bodySmall),
|
|
],
|
|
),
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|