From 5b4f3f7ec22c7076939142fbc7d916dd2395f1bd Mon Sep 17 00:00:00 2001 From: alexis Date: Sun, 12 Jul 2026 00:05:01 +0200 Subject: [PATCH] =?UTF-8?q?restreindre=20+=20et=20recherche=20=C3=A0=20cer?= =?UTF-8?q?tains=20=C3=A9crans;=20rendre=20les=20comptes=20modifiables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app.dart | 22 +++++---- lib/screens/accounts_screen.dart | 84 +++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 0ca07f7..fbb96d4 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -158,16 +158,18 @@ class _YnabAppState extends ConsumerState { tooltip: 'Fermer la recherche', ) else ...[ - IconButton( - icon: Icon(Icons.add, color: colorScheme.primary), - onPressed: _addTransaction, - tooltip: 'Ajouter une transaction', - ), - IconButton( - icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant), - onPressed: _toggleSearch, - tooltip: 'Rechercher', - ), + if (selectedIndex == 0 || selectedIndex == 3) + IconButton( + icon: Icon(Icons.add, color: colorScheme.primary), + onPressed: _addTransaction, + tooltip: 'Ajouter une transaction', + ), + if (selectedIndex == 2 || selectedIndex == 3) + IconButton( + icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant), + onPressed: _toggleSearch, + tooltip: 'Rechercher', + ), ], ], ), diff --git a/lib/screens/accounts_screen.dart b/lib/screens/accounts_screen.dart index 9f860be..dab7177 100644 --- a/lib/screens/accounts_screen.dart +++ b/lib/screens/accounts_screen.dart @@ -1,3 +1,5 @@ +import 'package:drift/drift.dart' show Value; +import '../data/db.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/db_provider.dart'; @@ -23,7 +25,7 @@ class AccountsScreen extends ConsumerWidget { } } -class _AccountCard extends StatelessWidget { +class _AccountCard extends ConsumerWidget { final Account account; const _AccountCard({required this.account}); @@ -47,7 +49,7 @@ class _AccountCard extends StatelessWidget { } @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { return Card( margin: const EdgeInsets.only(bottom: 8), child: ListTile( @@ -64,7 +66,85 @@ class _AccountCard extends StatelessWidget { color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error, ), ), + onTap: () => _editAccount(context, ref, account), ), ); } + + Future _editAccount(BuildContext context, WidgetRef ref, Account account) async { + final db = ref.read(dbProvider); + final nameCtrl = TextEditingController(text: account.name); + final balanceCtrl = TextEditingController(text: account.balance.toStringAsFixed(2)); + String type = account.type; + + await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: const Text('Modifier le compte'), + content: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: nameCtrl, + decoration: const InputDecoration(labelText: 'Nom', hintText: 'Ex: Compte courant'), + ), + const SizedBox(height: 12), + TextField( + controller: balanceCtrl, + decoration: const InputDecoration(labelText: 'Solde', hintText: '0,00'), + keyboardType: const TextInputType.numberWithOptions(decimal: true), + ), + const SizedBox(height: 12), + DropdownButtonFormField( + value: type, + decoration: const InputDecoration(labelText: 'Type'), + items: const [ + DropdownMenuItem(value: 'checking', child: Text('Compte courant')), + DropdownMenuItem(value: 'savings', child: Text('Épargne')), + DropdownMenuItem(value: 'credit', child: Text('Carte de crédit')), + DropdownMenuItem(value: 'cash', child: Text('Espèces')), + ], + onChanged: (v) { + if (v != null) type = v; + }, + ), + ], + ), + ), + actions: [ + TextButton( + onPressed: () async { + await (db.delete(db.accounts)..where((t) => t.id.equals(account.id))).go(); + if (ctx.mounted) Navigator.pop(ctx); + }, + style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.error), + child: const Text('Supprimer'), + ), + const Spacer(), + TextButton( + onPressed: () => Navigator.pop(ctx), + child: const Text('Annuler'), + ), + FilledButton( + onPressed: () async { + final name = nameCtrl.text.trim(); + final balanceStr = balanceCtrl.text.trim().replaceAll(',', '.'); + final balance = double.tryParse(balanceStr); + if (name.isEmpty || balance == null) return; + await (db.update(db.accounts)..where((t) => t.id.equals(account.id))).write(AccountsCompanion( + name: Value(name), + type: Value(type), + balance: Value(balance), + )); + if (ctx.mounted) Navigator.pop(ctx); + }, + child: const Text('Enregistrer'), + ), + ], + ), + ); + nameCtrl.dispose(); + balanceCtrl.dispose(); + } }