ajout type dépense/revenu dans le dialogue transaction
This commit is contained in:
parent
83523b1811
commit
b321ebf7ed
25
lib/app.dart
25
lib/app.dart
|
|
@ -55,15 +55,16 @@ class _YnabAppState extends ConsumerState<YnabApp> {
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final payeeCtrl = TextEditingController();
|
||||
final amountCtrl = TextEditingController();
|
||||
int? accountId = accounts.first.id;
|
||||
DateTime date = DateTime.now();
|
||||
bool isExpense = true;
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
builder: (ctx) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
title: const Text('Nouvelle transaction'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
|
@ -81,6 +82,18 @@ class _YnabAppState extends ConsumerState<YnabApp> {
|
|||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SegmentedButton<bool>(
|
||||
segments: const [
|
||||
ButtonSegment(value: true, label: Text('Dépense'), icon: Icon(Icons.arrow_upward)),
|
||||
ButtonSegment(value: false, label: Text('Revenu'), icon: Icon(Icons.arrow_downward)),
|
||||
],
|
||||
selected: {isExpense},
|
||||
onSelectionChanged: (v) => setDialogState(() => isExpense = v.first),
|
||||
style: ButtonStyle(
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<int>(
|
||||
value: accountId,
|
||||
decoration: const InputDecoration(labelText: 'Compte'),
|
||||
|
|
@ -101,8 +114,9 @@ class _YnabAppState extends ConsumerState<YnabApp> {
|
|||
onPressed: () async {
|
||||
final payee = payeeCtrl.text.trim();
|
||||
final amountStr = amountCtrl.text.trim().replaceAll(',', '.');
|
||||
final amount = double.tryParse(amountStr);
|
||||
if (payee.isEmpty || amount == null || accountId == null) return;
|
||||
final raw = double.tryParse(amountStr);
|
||||
if (payee.isEmpty || raw == null || accountId == null) return;
|
||||
final amount = isExpense ? -raw.abs() : raw.abs();
|
||||
await db.into(db.transactions).insert(TransactionsCompanion.insert(
|
||||
accountId: accountId!,
|
||||
payee: payee,
|
||||
|
|
@ -115,9 +129,8 @@ class _YnabAppState extends ConsumerState<YnabApp> {
|
|||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
payeeCtrl.dispose();
|
||||
amountCtrl.dispose();
|
||||
}
|
||||
|
||||
void _toggleSearch() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue