fix dialog white screen: StatefulBuilder + remove Spacer from actions
This commit is contained in:
parent
5b4f3f7ec2
commit
993e4f62a1
|
|
@ -79,69 +79,74 @@ class _AccountCard extends ConsumerWidget {
|
||||||
|
|
||||||
await showDialog(
|
await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => StatefulBuilder(
|
||||||
title: const Text('Modifier le compte'),
|
builder: (context, setDialogState) => AlertDialog(
|
||||||
content: SingleChildScrollView(
|
title: const Text('Modifier le compte'),
|
||||||
child: Column(
|
content: SingleChildScrollView(
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
mainAxisSize: MainAxisSize.min,
|
||||||
TextField(
|
children: [
|
||||||
controller: nameCtrl,
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: 'Nom', hintText: 'Ex: Compte courant'),
|
controller: nameCtrl,
|
||||||
),
|
decoration: const InputDecoration(labelText: 'Nom', hintText: 'Ex: Compte courant'),
|
||||||
const SizedBox(height: 12),
|
),
|
||||||
TextField(
|
const SizedBox(height: 12),
|
||||||
controller: balanceCtrl,
|
TextField(
|
||||||
decoration: const InputDecoration(labelText: 'Solde', hintText: '0,00'),
|
controller: balanceCtrl,
|
||||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
decoration: const InputDecoration(labelText: 'Solde', hintText: '0,00'),
|
||||||
),
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||||
const SizedBox(height: 12),
|
),
|
||||||
DropdownButtonFormField<String>(
|
const SizedBox(height: 12),
|
||||||
value: type,
|
DropdownButtonFormField<String>(
|
||||||
decoration: const InputDecoration(labelText: 'Type'),
|
initialValue: type,
|
||||||
items: const [
|
decoration: const InputDecoration(labelText: 'Type'),
|
||||||
DropdownMenuItem(value: 'checking', child: Text('Compte courant')),
|
items: const [
|
||||||
DropdownMenuItem(value: 'savings', child: Text('Épargne')),
|
DropdownMenuItem(value: 'checking', child: Text('Compte courant')),
|
||||||
DropdownMenuItem(value: 'credit', child: Text('Carte de crédit')),
|
DropdownMenuItem(value: 'savings', child: Text('Épargne')),
|
||||||
DropdownMenuItem(value: 'cash', child: Text('Espèces')),
|
DropdownMenuItem(value: 'credit', child: Text('Carte de crédit')),
|
||||||
],
|
DropdownMenuItem(value: 'cash', child: Text('Espèces')),
|
||||||
onChanged: (v) {
|
],
|
||||||
if (v != null) type = v;
|
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();
|
nameCtrl.dispose();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue