diff --git a/lib/screens/accounts_screen.dart b/lib/screens/accounts_screen.dart index dab7177..f49002f 100644 --- a/lib/screens/accounts_screen.dart +++ b/lib/screens/accounts_screen.dart @@ -79,69 +79,74 @@ class _AccountCard extends ConsumerWidget { 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; - }, - ), - ], + builder: (ctx) => StatefulBuilder( + builder: (context, setDialogState) => 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( + initialValue: 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; + setDialogState(() {}); + } + }, + ), + ], + ), ), + 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 SizedBox(width: 8), + 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'), + ), + ], ), - 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();