fix dialog white screen: StatefulBuilder + remove Spacer from actions

This commit is contained in:
alexis 2026-07-12 00:08:46 +02:00
parent 5b4f3f7ec2
commit 993e4f62a1

View file

@ -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<String>(
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<String>(
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();